EasyUI Forum
April 29, 2024, 09:26:28 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Does the Datagrid column filter input has to match exactly with cell data?  (Read 1148 times)
JeroenvdV
Newbie
*
Posts: 21


View Profile Email
« 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
« Last Edit: December 25, 2023, 04:30:05 PM by JeroenvdV » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 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']
                },
...
Logged
JeroenvdV
Newbie
*
Posts: 21


View Profile Email
« Reply #2 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!