Kendo date range end date filtering

Trying to set the end date to filter the kendo grid as well. Right now the user can filter between two dates but if the user just enters the end date I need to filter the grid. Here is the code I’m using not sure what I’m missing. My grid is similar to this one with the end date not working http://jsfiddle.net/OnaBai/5bchz/86/

var orderDateFromFilter = $("#FromDate").val().split('-');
var orderDateToFilter = $("#ToDate").val().split('-');

if (orderDateFromFilter == "") {
    orderDateToFilter = "";
    $("#ToDate").val("");
    $("#input5").val("");
    $("#input6").val("");
}
else if (orderDateToFilter == "") {
    $("#ToDate").val($("#FromDate").val());
    $("#input6").val($("#input5").val());
    orderDateToFilter = orderDateFromFilter;
}

var mydate1 = new Date(orderDateFromFilter[0], orderDateFromFilter[1]-1, orderDateFromFilter[2]);
var mydate2 = new Date(orderDateToFilter[0], orderDateToFilter[1]-1, orderDateToFilter[2]);

var filter = { logic: "and", filters: [] };

    filter.filters.push({ field: "FilterByDate", operator: "gte", value: mydate1 });
    filter.filters.push({ field: "FilterByDate", operator: "lte", value: mydate2 });

    if (orderDateFromFilter== "" && orderDateToFilter == "")
        filter = "";
    grid.dataSource.filter(filter);
}
   

Answer

Adding this worked for me filter logic “filter” variable to this to have logic as “or” -> “var filter = { logic: “or”, filters: [] };”

Leave a Reply

Your email address will not be published. Required fields are marked *