EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: JeroenvdV on December 22, 2023, 03:39:49 AM



Title: Does the Datagrid column filter input has to match exactly with cell data?
Post by: JeroenvdV on December 22, 2023, 03:39:49 AM
Hi,

I have a question about the Datagrid Filter Row extension.

In my datagrid I have 'Users' column in where each cell contains the abbreviation of one or more users, see attachment "column_data.png". In the filter input bar I want it to be possible to type multiple user-abbreviations separated by a comma or space, for example: "jvdv rza", also see attachment "filter_input.png". The idea is that only rows are shown that have at least a user "jvdv" or "rza", see attachment "desired_result.png".

The filtering is done remotely and the data returned is correct, but it does not appear in the datagrid, the grid becomes empty.
My guess is that the Filter extension compares and checks again the returned data with the filter input (textbox) and only shows the rows that exactly match with the text entered in the filter input bar.
Is my guess correct? Does the filter extension checks the returned data to match with the text entered in the filter input bar?
If so, how can I bypass that?

Many thanks in advance and best regards,
Jeroen


Title: Re: Does the Datagrid column filter input has to match exactly with cell data?
Post by: jarry on January 02, 2024, 07:12:43 PM
The extended operators can be made to filter multiple values in the rows.
Code:
$.extend($.fn.datagrid.defaults.operators, {
    mcontains:{
        text:'Contains',
        isMatch:function(source,value){
            const vv = value.split(',').filter(r=>r);
            for(let i=0; i<vv.length; i++){
                const v = vv[i];
                if (source.indexOf(v) >= 0){
                    return true;
                }
            }
            return false;
        }
    }
})

This new operator can be applied to a filter input.
Code:
$('#dg').datagrid('enableFilter', [
                {
                    field:'Users',
                    type:'textbox',
                    op:['equal','mcontains']
                },
...


Title: Re: Does the Datagrid column filter input has to match exactly with cell data?
Post by: JeroenvdV on January 03, 2024, 12:34:03 AM
Thanks Jarry,

You pointed me in the right direction!
I made a minor adjustment to split on both commas and spaces.
Code:
var vv = value.split(/[\s,]+/); // split on both commas and spaces

Cheers,
Jeroen