Question

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)

Was it helpful?

Solution

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.

https://github.com/convenient/CollectionNoDb

OTHER TIPS

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() calls addFieldToFilter()
  • ::_prepareCollection() calls load()
  • ::_preparePage() calls setPageSize() and setCurPage()
  • ::_exportIterateCollection() calls getSize() and getLastPageNumber()
  • ...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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top