1

value is ReinsDepositAmount

enter image description here

**

output

**

enter image description here

I have recently stocked with one of the application date sorting in the kendo UI grid.

In kendo grid, the column name is defined 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
  3. 23/1/2015

So I have put the 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 the kendo grid. when I doing a demo with JSON files, its working fine. But the same thing applies 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 is 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.

Fateme Mirjalili
  • 762
  • 7
  • 16
Mohamed Sahir
  • 2,482
  • 8
  • 40
  • 71

2 Answers2

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.

Community
  • 1
  • 1
dimodi
  • 3,969
  • 1
  • 13
  • 23
  • 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,** – Mohamed Sahir Aug 12 '16 at 07:31
  • I have tried this also different format , but nothing gets works because i think it still taking as string , sorting is on the client side . so i put custom javascript `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; ` }` – Mohamed Sahir Aug 12 '16 at 09:00
  • Yes, your screenshot http://i.stack.imgur.com/WnR3b.png clearly indicates that the dates are actually strings in the Kendo UI DataSource. Until this is resolved, the built-in sorting cannot work correctly. You can compare your implementation with the examples on the Kendo UI site and the ones in this thread. I don't think that custom sorting is the best approach, as you will have the same problems with filtering and editing as well. – dimodi Aug 12 '16 at 09:23
  • ok cool thanks man for a response. Still one more confusion then how its working in this demo as string. Is there any alternative approach best to suite here. [link] http://fiddle.jshell.net/NqrDS/light/ and [link]http://jsfiddle.net/mackry/rbmaz/ – Mohamed Sahir Aug 12 '16 at 09:38
  • 1
    The dates in these examples are successfully parsed by the Kendo UI DataSource, so JavaScript Date objects are constructed and used in the Grid. I believe I already touched this topic in my reply above – dimodi Aug 12 '16 at 09:56
0

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.

Jose Tuttu
  • 418
  • 5
  • 15