How to Sort only the current page using Jquery Datatable

后端 未结 3 736
猫巷女王i
猫巷女王i 2020-12-06 13:29

I have been using Jquery datatable for many projects and it\'s working perfectly for all scenarios.

For my current project I require sorting to be happened only for

3条回答
  •  我在风中等你
    2020-12-06 13:48

    Before asking how to sort only current page we should answer following questions:

    • Why do we want to do such sorting?
    • Should we do it?
    • Does it have any sense?
    • What are the implications of such decision?

    When we want to execute a query and display the result list we are dealing with:

    • searching criteria
    • sorting criteria
    • pagination

    These three elements are strongly related and they clearly define what user sees on the screen.
    We can have for example following description:

    There is a list of actors. It is sorted by name and divided into pages (50 items per page). And we are on the third page.

    When we have such rules then user has good orientation in this list. He sees Michael Caine at the top and Shon Connery on the bottom of the page. When he wants to find Robert Duvall he knows he should go few pages further. And when he wants to see these actors sorted by age he simply resorts the lists and returns to first page.

    But what if we provide additional sorting only for current page? This would disturb cohesion of above system. How would it sound if we say to user:

    You are now seeing third page of sorted-by-name list of actors resorted (page) by age.

    What can this user gain by resorting only current page? Age hierarchy of actors with name starting with 'C'? At the top of the page there will be the oldest actor from this page. But user doesn't know if it the oldest actor in all the list. And if not then on which page should he look for older one? Such resorting is worthless and it overrides initial sorting (which had some value).

    Such resorting can also lead user to serious confusion. He can loose his orientation about original sorting and page sorting.

    Conclusions:

    I don't see any sense in providing sorting for single page. I find it harmful. So you should use it only if you have strong arguments for it.

提交回复
热议问题