Sorting after fnAddTr with fnStandingRedraw/fnDraw

Sorting after fnAddTr with fnStandingRedraw/fnDraw

poasispoasis Posts: 2Questions: 0Answers: 0
edited January 2014 in DataTables 1.9
First of all, thanks Allan so much for this library! Datatables are one of the most useful things I've found so far!

I'm running into a strange issue that I can't seem to track down. Here's the debugger info: http://debug.datatables.net/ifisoq

Basically what I do is initialize the table from dom elements, and after some user input, I call fnAddTr several times, then fnClearTable, then fnDraw. I've also tried fnStandingRedraw at the end, with the same results. What happens is that when I add new rows, they are not added in the correct position given the current sorting state of the table. Depending on the current sorting of the table, they are either displayed at the top or bottom as a group with internal sorting (for example, with values 'a' 'd' and 'e' in the table, if I added 'c' and 'b', the sorting would be 'b' 'c' 'a' 'd' 'e'. This would not be a huge issue if I could just re-sort the table by a function call, but the table retains this order. Filtering for the new row values works as expected; the only issue appears to be with the sort.

Is there any way I can fix this sort? Or is it something that I'll just have to work around?

Thanks!

Replies

  • allanallan Posts: 63,493Questions: 1Answers: 10,470 Site admin
    Great to hear that DataTables is proving to be useful for you!

    Thanks for the debug trace and the information! Although i'm struggling a little to visualise how the display should work. Which column should be used for the grouped sort? Are you able to PM me a link to the page perhaps?

    Thanks,
    Allan
  • poasispoasis Posts: 2Questions: 0Answers: 0
    Thanks for the quick response! Unfortunately I've got a pretty large back-end set up to handle the ajax requests, and the html used to generate my page has quite a lot of references to web.py. Maybe I can try to explain it a little better?

    I have 4 columns in the table, all of which are added as DOM elements. The first 2 are plain text (username and version), the third is a version dropdown, and the 4th is a simple checkbox. A user can modify or delete any record in the table using the version dropdown and the checkbox, along with a button that I placed in the table head. They can also add rows to the table by a form on the same page, which has an ajax call to process the user input, and then makes one or more calls to fnAddTr on success, with the last call followed by clearing and redrawing the table. I do that (rather than fnAddData) because I need to dynamically create some of the DOM elements for this table row, such as the dropdown and checkbox, with the appropriate javascript bindings and classes.

    After those rows are added to the table, if I try to sort on the first column (usernames), everything is sorted correctly but is sorted in two groups: the items that existed before the fnAddTr call, and the items that were added after. The same thing happens if I sort on any other column. I've checked through the Tr being added, and everything is exactly the same format as the existing rows in the table.

    I suppose I could completely regenerate the table after every data addition, but in production this table could be quite large and I'm concerned about speed. Because part of the table will be data from an ajax request, and part will be dynamically generated form elements, this might be quite slow.
This discussion has been closed.