Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mopster opened this issue Aug 19, 2020 · 0 comments
Open

Comments

@Mopster
Copy link

Mopster commented Aug 19, 2020

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
Projects
None yet
Development

No branches or pull requests

2 participants