Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Kendo Grid column as DateTime but ignore Time when filtering

I have a Kendo Grid and a column "Sale Time" displayed as MM/dd/yyyy HH:mm a (1/3/2015 2:34 PM).

Now I want to be able to filter by Date only, ignoring the Time. But by default, the filter is looking at Time, so any date I filter using "Is Equal To" returns no results.

Here's a JSFiddle I made to illustrate the issue: http://jsfiddle.net/dmathisen/yx7huvxp/

And some code so I can post the jsfiddle link :)

columns: [
    { field: "ModelName", title: "Model" },
    { field: "DefaultMonoCPP", title: "Mono Cost" },
    { field: "SaleTime", title: "Sale Time", format: "{0:g}" }
]
like image 808
dmathisen Avatar asked Dec 29 '25 08:12

dmathisen


1 Answers

You can define a schema.parse function that generates an additional field called SaleDate that contains only the Date part of the SaleTime.

Then, when showing the columns in the grid, you use this.

Something like:

// Schema definition
schema: {
    model: {
        id: "ModelID",
        fields: {
            ModelName: { type: "string" },
            DefaultMonoCPP: { type: "number" },
            SaleTime: { type: "date" },
            SaleDate: { type: "date" }  // Additional field with the `Date` of `SaleTime`
        }
    },
    parse: function(d) {
        $.each(d, function(idx, elem) {
            // Compute SaleDate from SaleTime
            elem.SaleDate = kendo.parseDate(elem.SaleTime, "MM/dd/yyyy");
        });
        return d;
    }        
}

// Columns definition
columns: [
    {
        field: "ModelName",
        title: "Model"
    },
    {
        field: "DefaultMonoCPP",
        title: "Mono Cost"
    },
    {
        field: "SaleDate",
        title: "Sale Time",
        template: "#= kendo.toString(SaleTime, 'g') #"
    }
],

Your JSFiddle modified here: http://jsfiddle.net/OnaBai/yx7huvxp/10/

like image 112
OnaBai Avatar answered Jan 01 '26 00:01

OnaBai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!