Node order after drop

Node order after drop

philsephilse Posts: 14Questions: 0Answers: 0
edited December 2012 in General
I realized that my drag and drop script for row reordering was only working on the current page of rows, which is not a good thing. I was iterating through the rows using $(this).parents('table').find('tr').each(function() {...} I'm trying to alter the script and I found that I can iterate through all the nodes using $(oTable.fnGetNodes()).each(function () {...})

Here's what I can't figure out though...the above code iterates through the nodes in the original order they were displayed in the table, not the order after dropping a row. Is there a way to get the nodes in the order they are currently in instead of when the table loaded?

Thanks for the help!

Replies

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin
    Use the $ API method: http://datatables.net/docs/DataTables/1.9.4/#$

    Allan
  • philsephilse Posts: 14Questions: 0Answers: 0
    edited December 2012
    if I do this:

    oTable.$('tr').each(function() { ... }

    it's still not picking up the new order. Tried forcing the current order with this:

    oTable.$('tr', { 'order': 'current' }).each(function() { ... }

    but it still used the original order. Am I using the $ API method correctly?

    The good news is that it's iterating through all the pages now...
  • philsephilse Posts: 14Questions: 0Answers: 0
    I think I might know what's going on. The oTable.$('tr').each(function() { ... } isn't taking into account the where the dropped row is...it's using the order that dataTables has stored before the row was dropped. $(this).parents('table').find('tr').each(function() {...} used the current state of the table after the row was dropped which is why it was working, but only for the current page since those are the only visible rows.

    I think what I need to do is update the row that I'm moving first, then go through my loop.
  • philsephilse Posts: 14Questions: 0Answers: 0
    That didn't work because I end up with duplicate indexes. Back the drawing board. I've been trying out the drag and drop row plugin on the site, but it's not very clean in setting the order index, especially when you insert new items with the Editor. I've ended up with duplicate indexes, negative indexes, and skipped indexes. If I can just get $(this).parents('table').find('tr').each(function() { ... } to get every row in the table, I'll be good...or do away with paging.
  • philsephilse Posts: 14Questions: 0Answers: 0
    edited December 2012
    I found a bit of a work around. When using paging and reordering, you really don't care about anything other than the page you're working on...because you can't reorder something you can't see. By using the _iDisplayStart property, I was able to determine my starting point regardless of what page I'm on and how many items I'm displaying. I can then use that to add to the index numbering and to pass to my service to set the sort order properly.

    Now I just need to figure out how to get back to the page I was on when doing fnDraw(): DONE
This discussion has been closed.