filterColumns

I'm using the following code in the databound event of the grid control.

            grid.filterColumn([{ field: "Status", operator: "equal", predicate: "or", value: "Completed" }, { field: "Status", operator: "equal", predicate: "or", value: "Review" }]);

But this give me unpredictable results.  It usually just filters for "Complete" in the grid, but marks "Review" in the filter dropdown. (I'm using excel filtering)

Ultimately I want something like this, but need to get the above to work first.
/           grid.filterColumn([{ field: "OCPvDC", operator: "equal", value: "us01vcore5vc1" }, { field: "Status", operator: "equal", predicate: "or", value: "Completed" }, { field: "Status", operator: "equal",  predicate: "or", value: "Review" }]);

Thanks,
Mike


5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team October 27, 2017 04:02 PM UTC

Hi Michael, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and we suspect that you want to filter the Grid at initial rendering. So, we suggest you to use the filteredColumns property of filterSettings in ejGrid control. 

Refer the below code example. 


@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        .AllowFiltering(true) 
        .AllowPaging() 
 
        .FilterSettings(filter => filter.FilterType(FilterType.Excel) 
            .FilteredColumns(filcol => 
                    {  
                        filcol.Field("OrderID").Operator(FilterOperatorType.Equals).Value("10248").Predicate("or").Add(); 
                        filcol.Field("OrderID").Operator(FilterOperatorType.Equals).Value("10249").Predicate("or").Add();  
                    } 
            )) 
        .Columns(col => 
        { 
             
          ---- 
 
        })) 


We have prepared a sample and it can be downloadable from the below location. 


Refer the help documentation. 



Regards, 
Thavasianand S. 



ML Michael Lambert October 30, 2017 06:04 PM UTC

That works if the statement is put there, but a decision first needs to be made whether to filter or not so I think I need to apply the filter somewhere else.  I though in the DataBound event, but that doesn't work.  The controller can be called with a filter variable or not.

    function GridBound(args) {
        var val = '@ViewBag.PvDCFilter.ToString()';
        var grid = $("#OneCloudGrid").ejGrid("instance");
        if (val == "NoFilter")
            grid.clearFiltering();
        else {             

                grid.filterColumn([{ field: "OCPvDC", operator: "equal", value: val }, { field: "Status", operator: "equal", predicate: "or", value: "Completed" },      {   field: "Status", operator: "equal",  predicate: "or", value: "Review" }]);         
        }
    }




TS Thavasianand Sankaranarayanan Syncfusion Team October 31, 2017 04:29 PM UTC

Hi Michael, 

Based on your query, we suspect that you want to filter the column of same fields with different values in the filterColumn method. So, we suggest that to use filteredColumns API at initial filtering.  

If you want to filter the column after the Grid rendered then we suggest you to pass the filteredColumns in the Grid model and call for the refreshContent() of ejGrid control. 

We have filter the OrderID column by using the external button click event. 

Refer the below code example. 


<button type="button" onClick="refreshData()">FilterColumn</button> 
 
<div style="padding-top:10px"> 
    @(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        .AllowFiltering(true) 
        .AllowPaging() 
             
        .FilterSettings(filter => filter.FilterType(FilterType.Excel)) 
        .Columns(col => 
        { 
            
           --- 
 
        })) 
</div> 
 
    <script type="text/javascript"> 
        function refreshData(args) { 
 
            var gridObj = $("#FlatGrid").ejGrid('instance'); 
 
            gridObj.model.filterSettings.filteredColumns = [{ field: "OrderID", operator: "equal", predicate: "or", value: "10248" }, { field: "OrderID", operator: "equal", predicate: "or", value: "10249" }]; 
 
           gridObj.refreshContent(); 
        } 
    </script> 



We have prepared a sample and it can be downloadable from the below location. 

 
Refer the help documentation. 



Regards, 
Thavasianand S. 



ML Michael Lambert October 31, 2017 06:45 PM UTC

Worked great!  Thanks



TS Thavasianand Sankaranarayanan Syncfusion Team November 1, 2017 04:12 AM UTC

Hi Michael, 
 
We are happy that the problem has been solved at your end. 
 
Please get back to us if you need any further assistance.  
 
Regards, 
Thavasianand S. 
 


Loader.
Up arrow icon