3

I want to get increment id whenever filter is applied to the sales order grid.And When filter is cleared i need to revert the changes.

This is what i have done so far:

$collection = $this->getCollection();
foreach ($collection as $item) {
    if (check whether filter is applied) {
        echo $item->getData('increment_id');
    }
}

How do i detect whether the filter is applied or not??

  • In which file you are using above code? php, phtml? – John Jun 22 '17 at 9:56
  • @John i'm using it in grid.phtml – passion Jun 22 '17 at 10:00
  • Can you please add full path of your file? – John Jun 22 '17 at 10:02
  • app/design/adminhtml/default/default/template/widget/grid.phtml – passion Jun 22 '17 at 10:06
3

You can use $this->getParam($this->getVarNameFilter(), null); to check whether filter is applied or not to the collection.

So try below code.

$collection = $this->getCollection();
$filter     = $this->getParam($this->getVarNameFilter(), null);
foreach ($collection as $item) {

    //allows only when filter is applied
    if ($filter) {
        echo $item->getData('increment_id');
    }
}
1

You can try below code.

$filter = $this->getRequest()->getParam('filter');
$collection = $this->getCollection();
foreach ($collection as $item) {
    if ($filter) {
        echo $item->getData('increment_id');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.