KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How do I filter collection by default? #2999

Open jernej opened this topic on on Feb 26, 2023 - 1 comments

jernej commented on Feb 26, 2023

Greetings,

In Admin Panel in Resource class, how do I put a filter/where to query that would be applied automatically as additional where after all other filters or/and search is completed? If is use query or getQuery functions to add "where" to query, then search doesn't work anymore.

Thank you, Jernej

jernej commented on Feb 26, 2023

Actually, I think the search should be improved. Right now, it adds search string as orWhere sql statements. On my opinion, search should act as a grouped where. So in class SQLHandler, I propose that search is changed from

        if($this->search()!==null) {
            $search = $this->search();
            foreach($search["fields"] as $field) {
                $query->orWhere($field,"LIKE","%".$search['text']."%");
            }
        }

to

        if($this->search()!==null) {
            $search = $this->search();
            $query->where(function ($query) use ($search) {
                foreach($search["fields"] as $field) {
                    $query->orWhere($field,"LIKE","%".$search['text']."%");
                }
            });
        }

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Dashboard