Identifying rows when dragging and dropping

Identifying rows when dragging and dropping

alhendersonalhenderson Posts: 9Questions: 0Answers: 0
edited December 2012 in General
I have a datatable where I have disabled sorting on all but one hidden column to allow me to control the order of rows. I am also using the jQueryUI 'sortable' plugin to allow users to drag and drop rows within the table. This all works quite nicely, but I have a couple of issues which I'm really struggling with.

I have some controls which get conditioned based on a selected row's position in the table. Specifically, if the row is the very first one in the table (not just the first one on a page), then I need to disable some stuff. I'm struggling to work out how I can tell if the selected row is the very first one in the table. Something like $("#table tbody tr:eq(0)") will work, but will also make report the first row on pages 2, 3, 4 etc of the table as being top due to the way that datatables hides unseen rows from the DOM. I can't use the datatables fnGetPosition API either as those positions don't seem to keep up to date with the changes introduced by any dragging and dropping of rows.

In a similar vein, when a user drags a row I need to work up or down the DOM to identify other rows related to it for various reasons. I need to be able to iterate over all rows in the table, but again the order needs to reflect any changes caused by dragging and dropping.

Does anyone have any bright ideas that might help?

Thanks,
Al.

Replies

  • alhendersonalhenderson Posts: 9Questions: 0Answers: 0
    My post above is possibly a little vague, so here's some more details.

    My hidden column in the table contains a display order which just allows me to remember the order of the rows (stored in the database). When a row is dragged, I use fnUpdate to update this column and the table then shows everything in the correct order. If I were to drag a row above the current first row in the table, subsequent calls to fnGetData(0) (which I think should get me the first row in the table?) return the original top row and not the new one.

    Maybe that makes things clearer..

    Thanks,
    Al.
  • alhendersonalhenderson Posts: 9Questions: 0Answers: 0
    Think I've answered my own question - the $ API seems to do the trick. Specifically:

    oTable.$("tr :eq(0))

    Superb :-) I think that will probably solve my second problem as well.

    Thanks Allan - great tool.

    Al.
This discussion has been closed.