Why kendo Ui -grid date is not sorting properly?

2019-03-06 12:44发布

问题:

value is ReinsDepositAmount

**

output

** i have recently stucked with one of the application date sorting in kendo ui grid.

In kendo grid , the column name is define like this

Incoming value to ReinsDepositDate - Month,date,year format. 08-23-1991

Field name is ReinsDepositDate: { field: "ReinsDepositDate", type: "date", title: "Due Date",format: "{0:M/d/yyyy}", width: 100, filterable: { cell: { operator: "contains"
} } },

When Sorting the date , its sorting based on first values

  1. 1/12/1994
  2. 23/1/2015
  3. 13/1/1992

means while ascending i am getting

  1. 1/12/1994 2.13/1/1992
  2. 23/1/2015

So i have put schema model

still i am getting the same result.

 schema: {
                model: {
                    fields: {
                        ReinsDepositDate: { type: "date",format: "{0:dd/MM/yyyy}"}
                    }
                }
            },

I have seen lots of fiddle demos nothing works here why:

Refrences: http://fiddle.jshell.net/NqrDS/light/ Kendo grid date column not formatting

Flow of Design:

Flow of design is by using angular http service get the value from db through api and assign the response to datasource in kendo grid. when i doing a demo with json files , its working fine. But same thing apply it here means not working. so i went to custom javascript to sort. columns:[$scope.grdPrmiumDepositCol, –

Custom javascript in kendo sortable attribute will do the trick . working fine do this part.

 { field: "ReinsDepositDate", format: "{0:MM/dd/yyyy}",type:"date",  sortable:{  compare: function (a, b) {
                           var c = new Date(a.ReinsDepositDate);
                            var d = new Date(b.ReinsDepositDate);
                            return c - d;
                        }`

                    }}],

My Question is why i do that because kendo given the date format and when i tried the sample demo with transport read with json file working fine with kendo format. Still in confusion.

回答1:

Based on the provided information, it is unclear if sorting is performed on the client, or on the server.

If sorting is done on the client by the Kendo UI DataSource, then the date values should be provided in the correct format, so that they are parsed to JavaScript Date objects by Kendo UI. There are multiple different formats that can be parsed, but dd-MM-yyyy is not one of them.

Here is an example, which demonstrates the above. You will notice the empty row, where the date has not been parsed.

http://dojo.telerik.com/UcEXO/2

Generally, it is recommended to serialize dates using commonly accepted standards:

https://stackoverflow.com/a/15952652/3086237

If sorting is performed on the server, then Kendo UI is unrelated to the problem and you should debug the server-side implementation.



回答2:

You can try parsing the date from response.

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.parse

schema: {
    parse: function(response) {
      for (var i = 0; i < response.length; i++) {
        response[i].ReinsDepositDate = kendo.parseDate(response[i].ReinsDepositDate, "dd/MM/yyyy");
      }
      return response;
    }
  }

Hope this helps.