user3506989
user3506989

Reputation: 11

Kendo Grid Culture specific date format

I am creating a simple kendo grid something like this -

 $("#grid").kendoGrid({
                    dataSource: {
                        type: "odata",
                        transport: {
                            read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                        },
                        schema: {
                            model: {
                                fields: {
                                    OrderID: { type: "number" },
                                    Freight: { type: "number" },
                                    ShipName: { type: "string" },
                                    OrderDate: { type: "date" },
                                    ShipCity: { type: "string" }
                                }
                            }
                        },
                        pageSize: 20,
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    height: 550,
                    filterable: true,
                    sortable: true,
                    pageable: true,
                    columns: [{
                            field:"OrderID",
                            filterable: false
                        },
                        "Freight",
                        {
                            field: "OrderDate",
                            title: "Order Date",
                            format: "{0:MM/dd/yyyy}"
                        }, {
                            field: "ShipName",
                            title: "Ship Name"
                        }, {
                            field: "ShipCity",
                            title: "Ship City"
                        }
                    ]
                });

My problem is format: "{0:MM/dd/yyyy}".

I don't want to hardcode the format, I want it to be culture specific. My web application => web.config has culture information set. I also tried kendo.culture("some culture code") but it didn't work.

If I remove format it shows me big date string like this, Please help?

screen shot

Upvotes: 0

Views: 2593

Answers (2)

The Dread Pirate Stephen
The Dread Pirate Stephen

Reputation: 3169

A couple things you need to do:

Include the kendo culture script for the culture you want to use, i.e.

<script src="http://kendo.cdn.telerik.com/2017.1.223/js/cultures/kendo.culture.en-CA.min.js"></script>

Use kendo.culture("en-CA"); with the culture code from the script you included.

Set the format on the date column as just a date, without a specific format

"Freight",
{
    field: "OrderDate",
    title: "Order Date",
    format: "{0:d}"
}

Example: http://dojo.telerik.com/@Stephen/OlAdI

Upvotes: 1

DaniDev
DaniDev

Reputation: 2631

You can try using the following libraries. They have both Jquery and non Jquery options https://github.com/phstc/jquery-dateFormat

They have worked well with me for Kendo widgets, but I have not fully tested for culture specific context.

Upvotes: 0

Related Questions