0

I tried with sample data using below JS code:

$(document).ready(function () {

    var PraksysDateFormats = ["dd-MM-yyyy", "dd/MM/yyyy", "dd-MM-yy", "dd/MM/yy", "dd.MM.yy", "ddMMyy", "ddMM", "dd.MM.yyyy", "ddMMyyyy"];

    relationDataSource = new kendo.data.DataSource({
        data: [
        { ProductName: "Computer", UnitPrice: 100, UnitsInStock: 5, Discontinued: false, FromDate: new Date(kendo.toString(kendo.parseDate("10-11-2016", 'dd-MM-yyyy'), 'yyyy-MM-dd')), ToDate: new Date(kendo.toString(kendo.parseDate("11-11-2016", 'dd-MM-yyyy'), 'yyyy-MM-dd')) },
        { ProductName: "TV", UnitPrice: 1000, UnitsInStock: 5, Discontinued: false, FromDate: new Date(kendo.toString(kendo.parseDate("20-10-2016", 'dd-MM-yyyy'), 'yyyy-MM-dd')), ToDate: new Date(kendo.toString(kendo.parseDate("22-10-2016", 'dd-MM-yyyy'), 'yyyy-MM-dd')) },
        ],
        schema: {
            model: {
                fields: {
                    ProductName: { type: "string" },
                    UnitPrice: { type: "number" },
                    UnitsInStock: { type: "number" },
                    Discontinued: { type: "boolean" },
                    FromDate: { type: "date" },
                    ToDate: { type: "date" }
                }
            }
        },
    });


    var grid = $("#grid").kendoGrid({
        dataSource: relationDataSource,
        scrollable: true,
        sortable: true,
        //editable: true,
        filterable: true,
        columns: [
            { field: "ProductName", title: "Product Name" },
            { field: "UnitPrice", title: "Unit Price", format: "{0:c}" },
            { field: "UnitsInStock", title: "Units In Stock" },
            { field: "Discontinued", title: "Discontinued" },
            {
                field: "FromDate", title: "From Date", editor: FromDatePicker, width: 200, format: "{0:dd-MM-yyyy}", filterable: {
                    ui: dateFilter
                }
            },
            {
                field: "ToDate", title: "To Date", editor: ToDatePicker, width: 200, format: "{0:dd-MM-yyyy}", filterable: {
                    ui: dateFilter
                }
            }
        ],
        edit: function (e) {
            var grid = this;
            var fieldName = grid.columns[e.container.index()].field;
            // alert(fieldName)
        },
        save: function (e) {
            var grid = this;
            var fieldName = grid.columns[e.container.index()].field;
            // alert(e.container.index());
            // alert(fieldName)
            var productName = e.values.ProductName || e.model.ProductName;
            var relation = e.values.Relation || e.model.Relation;
            var dataItem = this.dataSource.getByUid(e.model.uid);
            dataItem.set("ProductName", productName);
            dataItem.set("UnitPrice", 9000);
            dataItem.set("UnitsInStock", 99);
            dataItem.set("Discontinued", true);
        },
        update: function (e) {
            alert("Update")
        }
    }).data("kendoGrid");


    function FromDatePicker(container, options) {
        alert(options.field);
        $('<input id="BrugergyldigFradato"  name="FromDate" dynamicfield="71" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDatePicker({
                format: "dd-MM-yyyy",
                parseFormats: PraksysDateFormats,
                culture: "da-DK"
            });
        $('<span class="k-invalid-msg" data-for="FromDate"></span>').appendTo(container);
    };
    function ToDatePicker(container, options) {
        alert(options.field);
        $('<input id="BrugergyldigTildato"  name="ToDate" dynamicfield="71" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDatePicker({
                format: "dd-MM-yyyy",
                parseFormats: PraksysDateFormats,
                culture: "da-DK"
            });
        $('<span class="k-invalid-msg" data-for="ToDate"></span>').appendTo(container);
    };


    function dateFilter(element) {
        element.kendoDatePicker({
            format: "dd-MM-yyyy",
            culture: "da-DK"
        });
    };

});

I am able to filter all columns, except last 2 date fields. On entering a date field filter value, it's making the grid blank. My date format is "dd-MM-yyyy". Any clue here would be appreciated.

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
Jaish Mathews
  • 766
  • 1
  • 9
  • 25

2 Answers2

0

Don't use new Date in your datasource.

On my browser(chrome):

new Date("2016-11-11") 
Fri Nov 11 2016 02:00:00 GMT+0200

As you see date is converted to local time here. But when you filter with 11-11-2016 your filter will not be converted. In that case your filter value will be

Fri Nov 11 2016 00:00:00 GMT+0200

Therefore equality check fails.

Instead you can use only kendo.parseDate to assign your date values and it will work.

 data: [
    { ProductName: "Computer", UnitPrice: 100, UnitsInStock: 5, Discontinued: false, FromDate: kendo.parseDate("10-11-2016", 'dd-MM-yyyy'), ToDate: kendo.parseDate("11-11-2016", 'dd-MM-yyyy') },
    { ProductName: "TV", UnitPrice: 1000, UnitsInStock: 5, Discontinued: false, FromDate: kendo.parseDate("20-10-2016", 'dd-MM-yyyy'), ToDate: kendo.parseDate("22-10-2016", 'dd-MM-yyyy') },
 ],
uygar donduran
  • 1,177
  • 1
  • 9
  • 20
0

This turnout to be a formatting issue and now working as expected

Jaish Mathews
  • 766
  • 1
  • 9
  • 25