EasyUI Forum

General Category => Bug Report => Topic started by: rkpunjal on January 03, 2015, 09:44:55 AM



Title: Datagrid Row Filter does-not work well with columns having formatter
Post by: rkpunjal on January 03, 2015, 09:44:55 AM
if you enabled filter on a datagrid using  $("#my-dg").datagrid('enableFilter');   and if your datagrid has a column with a formatter eg:
<th field="state" width="100px" sortable="true" formatter="cityMaster.showStateInGrid" ></th>
Then filtering won't work on that column.
Meaning typing into the filter-box will fail and blank-out the grid.

But I managed to fix this.
Attached is the filter plugin with the fix. I took the latest-code and applied my fix on this.
Features:
  • Automatically uses the formatter specified in the datagrid for that column and no need to write any extra code. Compares value with the formatted data.

    Works well with a combo-box setup in your filter. eg: as below

Code:
    $("#city-dg").datagrid('enableFilter', [
        {
            field:'state',
            type:'combobox',
            options:{
                panelHeight:'auto',
                data: filterStateComboboxData,  // my data for the combo-filter
                onChange:function(value){
                    if (value == null || value == ''){
                        $("#city-dg").datagrid('removeFilterRule', 'state');
                    } else {
                            $("#city-dg").datagrid('addFilterRule', {
                            field: 'state',
                            formatter: showStateInGrid,             // point to the formatter
                            op: 'equal',
                            value: value
                        });
                    }
                    $("#city-dg").datagrid('doFilter');
                }
            }
        }
    ]);


This works well !!

But I feel that the JEasy-UI developers should take a look at it and 'optimize' the code as per their coding standards.
Incase you choose to apply this as a patch, please let me know, so that I can download the latest filter-plugin then.

cheers,
Ram


Title: Re: Datagrid Row Filter does-not work well with columns having formatter
Post by: fguibert on February 12, 2019, 03:13:39 AM
+1 I had the same problem, filters behavior should be natively the same as sorters : using the column's real value instead of the formatted value.
thanks for the patch