I created a grid in the Magento admin, but the functionality like sort, filter and search doesn't work and that is because I didn't use a database table to get the information. I use a web service that connects with redmine and I get all the information. I reviewed and I founded that the default sort, search and filter of the Magento grid only works with models or collections, but I can't find a way to do the same but with my own collection (in this case the info that I get from the web service)
2 Answers
Thought I'd post this as I feel it contributes, but it does not fully answer your question.
I've recently hacked together something that supports an admin panel grid from a non-database source, however it was not built with web-service calls in mind.
It might be useful for people in the future if they want to embark on this kind of functionality to see what I've done.
-
Maybe you could expand on how you went about doing this? Commented Apr 28, 2015 at 15:04
-
Do you mean the approach I took to develop it? Or what the module is actually doing. Because if it's what the module is actually doing I suggest you look at the Readme on the github as well as this file. github.com/convenient/CollectionNoDb/blob/master/lib/Convenient/… Commented Apr 28, 2015 at 15:34
To be honest, it's a mess. As you point out, the Adminhtml grid widget assumes that it is working with a Varien_Data_Collection_Db
instance, yet this is not enforced in the code:
/**
* set collection object
*
* @param Varien_Data_Collection $collection
*/
//public function setCollection(Varien_Data_Collection $collection)
public function setCollection($collection)
{
$this->_collection = $collection;
}
This setter implies that the grid widget is built in a generic way, but there are several assumptions that the $_collection
object implements several methods from the collection class hierarchy:
::_addColumnFilterToCollection()
callsaddFieldToFilter()
::_prepareCollection()
callsload()
::_preparePage()
callssetPageSize()
andsetCurPage()
::_exportIterateCollection()
callsgetSize()
andgetLastPageNumber()
- ...et cetera...
You will need to map your resource set to a Varien_Data_Collection_Db
instance and each entity to a Varien_Object
to get this working. The more grid goodies you want to use (e.g. export to CSV), the more work you may need to do.
-
Which is why most 3rd parties that need to do exactly this rely on a windowed / iframe approach with an API key. Commented Dec 18, 2014 at 23:36
-
Then benmarks you suggest that I need create a table with the web service info and with that create a model and collection for use the grid options like sorting, filter, export to csv, etc? Commented Dec 18, 2014 at 23:36
-
@RicardoCortes - It's an option, and maybe a good one if say a 15min delay is okay. You could also wrap the API calls in the various methods of the expected classes. Your call!– benmarksCommented Dec 19, 2014 at 18:47