0

I created custom admin grid with filters. But when I enter 0 in "from field" in filter - in the results it shows items with negative values also, so it does not work right.

I found this function in magento core

vendor\magento\module-ui\Component\Filters\Type\Range.php

protected function applyFilterByType($type, $value)
{
    if (!empty($value) && $value !== '0') {
        $filter = $this->filterBuilder->setConditionType($type)
            ->setField($this->getName())
            ->setValue($value)
            ->create();

        $this->getContext()->getDataProvider()->addFilter($filter);
    }
}

If I comment this "if" statement it works right. How can I fix this in my module? How can I override Range class for my column?

1 Answer 1

0

In listing xml, inside < filters > tag

<filterRange name="amount" class="Vendor\Module\Ui\Component\Filters\Type\AmountRange" />

In Vendor\Module\Ui\Component\Filters\Type\AmountRange.php

namespace Vendor\Module\Ui\Component\Filters\Type;
class AmountRange extends \Magento\Ui\Component\Filters\Type\Range
{

/**
 * Apply filter by its type
 *
 * @param string $type
 * @param string $value
 * @return void
 */
  protected function applyFilterByType($type, $value)
  {

        $filter = $this->filterBuilder->setConditionType($type)
            ->setField($this->getName())
            ->setValue($value)
            ->create();

        $this->getContext()->getDataProvider()->addFilter($filter);

  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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