Grid Sorting is empty on the third time

4 posts, 1 answers
  1. Alberto
    Alberto avatar
    4 posts
    Member since:
    Jan 2016

    Posted 05 Feb 2016 Link to this post

    Hi All

     

    I am using kendo UI 2016.1.112 with angular and I am having an issue with sorting, the first time e.data.sort is populated nicely with the field and direction , second time same field and direction as desc but clicking for third time get an empty array

         

         dataSource: {
            transport: {
                read: function (e) {
                    if (!e.data.sort || e.data.sort.length === 0) {

                     ///WTH ..... WHY?

                    }
                    var sort = e.data.sort[0];
                    exclusionsService.getExclusions(e.data.skip, e.data.take, sort.field, sort.dir).then(function (data) {
                        e.success(data);
                    });
    ...

  2. Dimo
    Admin
    Dimo avatar
    8478 posts

    Posted 09 Feb 2016 Link to this post

    Hello Alberto,

    The observed behavior is expected - an empty array indicates that no sorting is currently applied.

    Do you by any chance want the Grid to not allow unsorted mode?

    http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-sortable.allowUnsort

    Regards,
    Dimo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Alberto
    Alberto avatar
    4 posts
    Member since:
    Jan 2016

    Posted 09 Feb 2016 in reply to Dimo Link to this post

    Hi Dimo

     

    The first time works fine, then click on the column to apply sorting by descendant, then clicking on the same column I one to sort it back as ascendant but array is empty, that is not happening on the demo found here http://demos.telerik.com/kendo-ui/grid/angular,

    In my code the maximum time I can click is twice.

     

     

  4. Answer
    Dimo
    Admin
    Dimo avatar
    8478 posts

    Posted 11 Feb 2016 Link to this post

    Hi Alberto,

    I am not sure I understand. Please do the following:

    1. Go to http://demos.telerik.com/kendo-ui/grid/angular
    2. Execute the following code in the browser's JavaScript console:

    $(".k-grid[options='mainGridOptions']").data("kendoGrid").dataSource.bind("requestStart", function(e) {
      console.log(e.sender.sort());
    });

    3. Click on any master Grid header cell to sort three times. You will see that the third time the sort method returns an empty array, which is normal, because the third time the column returns to unsorted state.

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-sort

    Here is a video:

    http://screencast.com/t/xqBfQvCC8Kiy

    If you want the column to be sorted ascending the third time, then set the allowUnsort property, as suggested earlier.

    Let me know if I am missing something.

    Regards,
    Dimo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top