How we can sorting only visible record in paging not all data?

How we can sorting only visible record in paging not all data?

HemanginiHemangini Posts: 7Questions: 2Answers: 0

Now when we click on sorting button is display last record first and first to last but I need those sort record which is in visible details like:
Below image display 10 records

when we click on Name column is display last data record you can see in below image:

but I need first image last record .
I need the Cedric Kelly record when we on first page.

Thanks in Advance.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 9,822Questions: 0Answers: 1,629
    Answer ✓

    This thread would help if you're using serverSide, otherwise that's not possible I'm afraid,

    Colin

  • HemanginiHemangini Posts: 7Questions: 2Answers: 0

    I have not used the serverSide option, When I add it throw the error.

  • HemanginiHemangini Posts: 7Questions: 2Answers: 0

    By mistake I have click on 'Yes' but the Answer is not working in my flow.

  • kthorngrenkthorngren Posts: 10,638Questions: 25Answers: 2,428

    That feature is not something built into Datatables. However it may be possible with some custom coding. In order to help we will need to know more about the requirements. Such as how do you determine the row you want to display at the bottom of each page?

    The easiest option would be to place that data into the footer. Is this an option for you?

    Please build a simple test case replicating your data with specifics of how you want to keep the certain row as the last row on the page.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Then we can take a look to see if there are options you can try.

    Kevin

  • HemanginiHemangini Posts: 7Questions: 2Answers: 0

    Hello Kevin

    Thanks for reply me.

    I need functionality like:

    Every time in my data table paging show only 10 rows. When I click on the sorting button in the header it will only do shorts those 10 records, not other page records.

    Current Datatable functionality work like first records sort with last and last record sort with first you can see in the below video.

    https://drive.google.com/file/d/1CYroPq7PPKH-aPeMHHAZ0gJd_pGPAgq9/view?usp=sharing

    If you are available for a call then send me your details and time we will meet and I will explain it with my data.

    Thanks.
    Hemangini.

  • kthorngrenkthorngren Posts: 10,638Questions: 25Answers: 2,428

    Every time in my data table paging show only 10 rows. When I click on the sorting button in the header it will only do shorts those 10 records, not other page records.

    Sorry, I misunderstood your initial description. I thought there was a particular row you always wanted to show. With client side Datatables the whole table will be sorted. As mentioned above, you could enable server side processing then you would write a server side script to handle the sorting the way you want.

    For client side I suspect the answer is still the same as this old thread.

    Kevin

  • colincolin Posts: 9,822Questions: 0Answers: 1,629

    Yep, and the answer in that thread is still correct. Unless you're using serverSide as I said in my comment above,

    Colin

  • kthorngrenkthorngren Posts: 10,638Questions: 25Answers: 2,428
    edited September 12

    Out of curiosity I decided to create an API plugin to sort the visible page only. It is a very simple plugin which supports sorting only one column and performs a string based sort. Multi column and multi type support can be added. It takes column visibility into consideration and supports either object or array based data. One of each type of table is in the example. And I disabled Datatables sorting.

    It uses the draw to call the plugin. The plugin basically iterates all the rows on the page to build an array of rows. Next it orders the array by the specified column and direction (asc or desc). Then re-writes the DOM table with the ordered array. Searching and paging seems to work with the plugin. Don't tell Allan that I'm accessing the settings directly :smile:

    Feel free to provide any input to make a better more efficient plugin. There may be a better way to update the DOM table.
    http://live.datatables.net/qukaxede/1/edit

    @Hemangini hope this gets you started on your solution.

    Kevin

  • allanallan Posts: 52,661Questions: 1Answers: 8,058 Site admin

    I'm accessing the settings directly

    WHAT!?

    Actually, in all seriousness, that's very clever - nice one Kevin! Also, accessing the internal settings I'd say is mostly okay in an API plug-in. It means there is a single point to update if we were ever to break the interface it uses.

    The downside to the way this plug-in is implemented, is that it won't use the same sorting as is applied to the table column - it is using the custom sort function. That will be fine for basic string and number data, but formatted dates and the like will trip over it. Also it is updating the DOM, but not DataTables internal ordering state (which might or might not be required) - so any filtering action or anything else triggering a draw (e.g. going to next page and then back) would reset the ordering back to what DataTables has it as.

    Creating a full plug-in for this in DataTables is probably not going to be trivial (to the point that I think it would be easier to add it to the core, than to try to create a plug-in for it). The way it works internally is there is a aoData array which contains the data for each row, in index order (i.e. the order it was added). Then there is a aiDisplayMaster array which contains the indexes to that array, ordered how it would be displayed. Finally there is a aiDisplay array, which is the same as that master array, but with filtering applied. aiDisplay is what is used to then draw the table.

    So to do this fully, we'd need to resort part of aiDisplay at least - possibly also aiDisplayMaster to allow for filtering.

    Kevin's solution is the most workable in the short term!

    Allan

  • kthorngrenkthorngren Posts: 10,638Questions: 25Answers: 2,428

    Thanks for the details Allan. Its good to know how these structures work. The complexity of this is why I stayed with the simplicity of sorting a string in one column :smile:

    Kevin

Sign In or Register to comment.