Load DataGrid with an exsiting Filter populated

I have a Staff datagrid which I have no filter in the definitions (45 rows show). I have a field called “Status” which can be the one of these choices: Active, Inactive, or NULL. My client wants to display a list of “Active” staff as a default. Like there is a filter value on the Status field, then hit CLEAR FILTERS to show all staff.

Is it possible to pre-set a filter on a load of a datagrid?

Also, when I filter for “Active”, inactive rows also show. Looks like a “contains” operator in the query.

Hello @dwdc!
Did you set your “Status” field to boolean type?

$crud->fieldType('Status', 'boolean')

Didn’t tested it , but I think you can set your filter using javascript events like this:

window.addEventListener('gcrud.datagrid.ready', ({detail}) => {
    groceryCrudSetQuickSearchValue('Status', 'Active');
});

No, the Status field is a VARCHAR(10). What I need is a EQUAL TO operator in the “Filter” where clause - not a LIKE.

As far as the addEventListener - will this run the filter query or just set the field to “Active”?

So the behavior desired is:

  1. on first load, enter “Active” into Status filter field, run the AJAX.

  2. Clear Filter Status, FIND ALL rows

Just give groceryCrudSetQuickSearchValue a try. It should work…