We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to set initial grid filter for null date column?

I'm trying to set an initial grid filter on page load, so that the DataManagerRequest in the Controller will filter the results for 2 columns. We do this in other places and it works fine, this is the first time I've tried to do it for a null date and can't get it to work.  We're using EJ2 grids in an ASP.NET application, Syncfusion version 17.1.50

The page is like:
    List<object> filterColumns = new List<object>();
    filterColumns.Add(new { field = "TaskStatus", matchCase = false, @operator = "notequal", predicate = "and", value = 9 });
    filterColumns.Add(new { field = "DueDate", matchCase = false, @operator = "notequal", predicate = "and", value = (DateTime?)null });

              .DataSource(ds => { ds.Url(Url.Action("LoadRecords", "Tasks")).Adaptor("UrlAdaptor"); })
              .AllowFiltering().FilterSettings(filter => filter.Columns(filterColumns).Type(FilterType.Menu))
              .Columns(col => {
                  col.Field(p => p.Id).IsPrimaryKey(true).IsIdentity(true).Visible(false).Add();
                  col.Field("CaseNumber").Width(100).HeaderText("Case ID").ValueAccessor("formatCaseNumber").Add();
                      .Filter(new { type = "CheckBox" }) // for FilterType.Menu
                  col.Field("DueDate").HeaderText("Due Date").Width(100).Type("date").Format("yMd").Add();

The Controller method is declared as:
public ActionResult LoadRecords(DataManagerRequest dataManager) {

While debugging the LoadRecords method, if I manually filter by DueDate it comes across in the DataManagerRequest with 2 predicates for Where[0], the first is TaskStatus as expected, and the 2nd predicate is Field = "DueDate", Operator = "notequal", value = null.

When I try to do it in code as described above, it also comes through in the DataManagerRequest with 2 predicates for the Where[0], the first is correct TaskStatus (same as above), but the 2nd predicate is blank with 2 child predicates - [0] is field = DueDate, Operator = "lessthanorequal", value = null, and the 2nd is field = "DueDate", Operator = "greatherthanorequal", value = null.

I can't figure out how to get the date to come through correctly programmatically, the same way it would work from the filter menu.  Any help would be appreciated.

Rich W.

2 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team September 4, 2019 02:07 PM UTC

Hi Richard, 
Thanks for contacting Syncfusion support. 
We have validated the provided code example and reported issue and we found the root cause of issue the filter value is not properly set for Date column(the null value changed as undefined while serializing  ). So we have achieved your requirement in the below way. Please find the code example for your reference. 
    List<object> filterColumns = new List<object>(); 
    filterColumns.Add(new { field = "EmployeeID", matchCase = false, @operator = "notequal", predicate = "and", value = 4 }); 
    filterColumns.Add(new { field = "ShippedDate", matchCase = false, @operator = "notequal", predicate = "and", value = (DateTime?)null }); 
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).AllowFiltering(true).Columns(col => 
   col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
   col.Field("EmployeeID").HeaderText("Employee ID").Width("150").Add(); 
   col.Field("OrderDate").HeaderText("Order Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add(); 
   col.Field("ShippedDate").HeaderText("Shipped Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add(); 
}).FilterSettings(filter => filter.Columns(filterColumns)).Load("load").AllowPaging().Render() 
    function load(args) { 
        this.filterSettings.columns.filter(function (e) { 
            if (!e.properties.value) { 
                e.properties.value = null; 
Thavasianand S.  

RW Richard Werning September 4, 2019 07:14 PM UTC

Thank you, this solved the problem I was seeing. However this just seems like a work around to a bug in your source. Are you going to fix this issue or am I really going to need to override the value in load if it's undefined every place we want to do something like this?

Thank you,
Rich W

Live Chat Icon For mobile
Up arrow icon