When I set datatable default sorting,limit is also change.

When I set datatable default sorting,limit is also change.

Zayar HtunZayar Htun Posts: 6Questions: 1Answers: 0

In my program,I was using the button on first column and I don't want it to sort.So,I disable its sorting and using ==>('order', [[1, 'asc']]);<=== It was ok.But,when I change the limit of my data row and make a sorting.The limit is set to default.

for example; I have choose the limit to 50 to display 50 rows.And then,I sort the second column .Then, the limit become to 10 again and just display10 rows.How can I fix?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,948

    Are you using server side processing?

    Kevin

  • Zayar HtunZayar Htun Posts: 6Questions: 1Answers: 0

    Yes.It was server side processing.

  • Zayar HtunZayar Htun Posts: 6Questions: 1Answers: 0

    It has been solved!!! I change ('order', [[1, 'asc']]); into ('order', [1, 'asc']);
    It is because of 2D array.It change the data from model to default limit.By the way,I was using datatable in cakephp :)

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    I think there must be something else going on - order should be a 2D array!

    Allan

  • Zayar HtunZayar Htun Posts: 6Questions: 1Answers: 0

    Yes.I think so,too. But I don't know the reason why? Please can you tell me if there is another way to solve?

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    I'd need a link to a test page showing the issue to have some idea of what is going wrong. Possibly the server-side script isn't correctly handling the 2D array?

    Allan

  • Zayar HtunZayar Htun Posts: 6Questions: 1Answers: 0

    In model, I was getting data from DB and order it like this ===>
    $sql->order([$colName => 'asc']); // $sql is 'Select * from table_name'

    And I post this data from model to controller and then to JS.
    In Js==>
    mytest.createTable().withOption('order', [1, 'asc']);

    The first column is button.So,It was sortable in model.So,I change it to unsortable.But arrow key is not disappear.That's why I inserted above code in js to auto change the second column to appear arrow. I think I have used 1D array in model.So,I can use 1Darray in JS with withOption.Is that right?

    P.S:Sorry about my english if there is something wrong.

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Ah I see - thanks for the explanation. DataTables should always be sending the ordering array to the server as a 2D array (since that it how it handles multi-column ordering). What you would probably need to do is just take the first element from that array in your server-side script and use that.

    Regards,
    Allan

  • Zayar HtunZayar Htun Posts: 6Questions: 1Answers: 0

    Thanks for your explain :) You give me many knowledge.

This discussion has been closed.