Deepanshu Tyagi
Deepanshu Tyagi

Reputation: 39

customized sorting in kendo ui grid in c#

In one of the columns of my grid in a view page ViewModel.cshtml, i used ".sortable" to sort the column. However the column is a date and my rows are sorted by days and month of the date but not the year. How to sort the rows by the whole date including day, month and year.

    @(Html.Kendo().Grid<viewmodel>()
                          .Name("SomeName")
                          .Sortable(x => x.Enabled(true))
                          .HtmlAttributes(new {style = "border: 1px solid black;"})
                          .DataSource(ds => ds
                              .Ajax()
                              .ServerOperation(false)
                              .Read(read => read.Action("someAction", "SomeController"))
                          )
                          .Events(e => e.DataBound("SomeDatabound"))

                          .Columns(c =>
                          {
                              c.Bound(m => m.Title1).Title("Title1").Width(300).Sortable(true);
                              c.Bound(m => m.CreatedDate).Title("CreatedDate").Sortable(true);                                 
                          })
                          .Resizable(resize => resize.Columns(true)))

Upvotes: 0

Views: 149

Answers (1)

Gergely Bakos
Gergely Bakos

Reputation: 90

If you follow these steps and set the column format like this:

columns.Bound(m => m.CreatedDate).Format("{0:yyyy.MM.dd.}").Title("CreatedDate").Sortable(true);

It should sort your column correctly.

(yyyy.MM.dd. is just an example)

Upvotes: 1

Related Questions