Skip to content

Filtering on 'not equals to' should return rows with 'null/empty' values #1057

Description

@Mopster

When filtering a column on 'not equals to' value A, my users expect the the grid to return also return rows where the value is empty, since it also doesn't equal 'A'.

With some testing, I found the following change did show this expected/wanted behaviour :

Original TextColumn :

    public function getFilters($source)
    {
        $parentFilters = parent::getFilters($source);

        $filters = [];
        foreach ($parentFilters as $filter) {
            switch ($filter->getOperator()) {
                case self::OPERATOR_ISNULL:
                    $filters[] = new Filter(self::OPERATOR_ISNULL);
                    $filters[] = new Filter(self::OPERATOR_EQ, '');
                    $this->setDataJunction(self::DATA_DISJUNCTION);
                    break;
                case self::OPERATOR_ISNOTNULL:
                    $filters[] = new Filter(self::OPERATOR_ISNOTNULL);
                    $filters[] = new Filter(self::OPERATOR_NEQ, '');
                    break;
                default:
                    $filters[] = $filter;
            }
        }

        return $filters;
    }

New :

    public function getFilters($source)
    {
        $parentFilters = parent::getFilters($source);

        $filters = [];
        foreach ($parentFilters as $filter) {
            switch ($filter->getOperator()) {
                case self::OPERATOR_ISNULL:
                    $filters[] = new Filter(self::OPERATOR_ISNULL);
                    $filters[] = new Filter(self::OPERATOR_EQ, '');
                    $this->setDataJunction(self::DATA_DISJUNCTION);
                    break;
                case self::OPERATOR_ISNOTNULL:
                    $filters[] = new Filter(self::OPERATOR_ISNOTNULL);
                    $filters[] = new Filter(self::OPERATOR_NEQ, '');
                    break;
                case self::OPERATOR_NEQ:
                case self::OPERATOR_NLIKE:
                case self::OPERATOR_NSLIKE:
                    $filters[] = new Filter(self::OPERATOR_ISNULL);
                    $this->setDataJunction(self::DATA_DISJUNCTION);
                    break;
                default:
                    $filters[] = $filter;
            }
        }

        return $filters;
    }

Would this be the correct way to do this ? Or what is the recommended implementation ? Would this be a possible PR for master ?
If not, is there a way to inject this behaviour instead of having to create my own column class with this ? (or change even more code in my forked version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions