Why kendo Ui -grid date is not sorting properly?

▼魔方 西西 提交于 2019-12-02 16:53:36

问题


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.



来源:https://stackoverflow.com/questions/38896594/why-kendo-ui-grid-date-is-not-sorting-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!