Reordering doesn't work!? (edit: Works not as expected)
Reordering doesn't work!? (edit: Works not as expected)
Hello
Is this just me?
http://jquery-datatables-row-reordering.googlecode.com/svn/trunk/default.html
https://datatables.net/extensions/rowreorder/examples/initialisation/simple.html
The only working example I found is here (when you hide the first column and use whole tr for reordering)::
https://datatables.net/extensions/rowreorder/examples/initialisation/selector.html
Also, when I try to set "ordering":false in first two examples it started to work but moves rows one position up or down only regardless how far do I place it
This question has an accepted answers - jump to answer
Answers
Moreover, I just noticed it only moves the first td, despite showing whole tr when drag, rest td's remain at their places on _mouseUp
The first link you provided is third party software and not supported my self.
The second example you gave appears to work exactly as expected for me. The sequence is reordered and the row is moved. For example if I move "Shou Itou" to the bottom of the page, that record is then sequence #10 and all the others on the page have their position increased by one.
Allan
Thank you for your time @allan and sorry for bothering you.
That was clearly my fault. I just didn't get how row reordering works here.
For my case I have rows with IDs (neither primary IDs, nor priorities) in the first column and some other data in another columns.
To be more specific let IDs and datas sequence look like:
203 | Field 1
244 | Field 2
265 | Field 3
289 | Field 4
When I drag and drop row 203 | Filed 1 to the very bottom I get:
a) With "ordering":false option:
244 | Field 2
203 | Field 1 <<< should be at the very bottom though but goes one step down only
265 | Field 3
289 | Field 4
NB: DOM structure changed
b) With "ordering":true option:
203 | Field 2
244 | Field 3
265 | Field 4
289 | Field 1 <<< data moved, but IDs remain at its original places
NB: DOM structure didn't change
I realized I have to add one extra column with priorities and set it to "visible":false (optionally) to make it work. And the fact is I don't want this extra column, I just want to reorder rows regardless any priorities and have it replaced "physically" in DOM and table stucture.
Finally I've used this approach in my case (jQuery.sortable() with tables). It suited my needs cause I didn't really need DT for certain case, but in the future I will need it within DT.
http://www.avtex.com/blog/2015/01/27/drag-and-drop-sorting-of-table-rows-in-priority-order/
DEMO: http://designpoodles.com/avtex/sortable-table/
Any ideas?
Thanks in advance
One more thing is that I've excluded this from the demo code so IDs move with its data
Hi,
Thanks for the clarification. The order in the DataTable always comes from the data - not the DOM (which is what
$.sortable()
does). So you need a column that contains the ordering sequence (even if that column is hidden so the user can't see it).The reason RowReorder takes this approach is that, generally speaking, I've assumed it would be used to update a server-side database to which DOM order is meaningless. It needs to update the data.
Does that make sense? Do you have a sequence column available?
Allan
Well it does make sense in my case and my approach
It might be lame but I'll try to explain it anyway:)))
I have a table called flashcards, every flashcard has multiple rules stored in rules table. To link it I use table called flashcard_rules. The structure is like:
flashcard_rules_id (primary key, auto_increment)
flashcard_id (related to flashcards ID)
rule_id (related to rules ID)
Ok let flashcard ID 51 has multiple rules linked, so the flashcard_rules table is filled like:
1 | 51 | 1645
2 | 51 | 1024
3 | 51 | 1556
First column is flashcard_rules_id and it's kinda priority for now, but I just use it to output rules in that order, I don't really need to output flashcard_rules_id itself and here's why:
First of all I do INNER JOIN rules names out of the table rules and then output some rows like:
1645 | Rule Name 1 | 51 <<< top rule row which I will drag and drop now
1024 | Rule Name 2 | 51
1556 | Rule Name 3 | 51
Last column is actually hidden for the client but that doesn't really matter
Lets reorder a bit:
1024 | Rule Name 2 | 51
1556 | Rule Name 3 | 51
1645 | Rule Name 1 | 51 <<< top rule row goes to very bottom
Now I need to UPDATE the table flashcard_rules, but what I actually do is:
1. DELETE FROM flashcard_rules WHERE flashcard_id = '51' (rows 1,2,3 deleted)
2. INSERT rows using known rule_ids and flashcard_id ordered by its places in DOM structure (rows 4,5,6 created)
Now the flashcard_rules table is filled like:
4 | 51 | 1024
5 | 51 | 1556
6 | 51 | 1645
So my links got new IDs and ordered as I expect it to be.
Hope the explanation is clear cause my English in not that fluent:)
Thanks for the explanation - that does help, and I'm afraid that isn't a task that Editor was designed for. It was specifically designed to update sequences, rather than inferred data. A future enhancement would be to allow it to callback and update if needed, but at the moment the best I could suggest is that you insert a sequence if you want to use RowReorder rather than something like jQuery UI's sortable.
Allan
Thanks anyway! I'll be glad if you keep it in mind:)
P.S. I am not using Editor for now, DataTables only. I am excited to use Editor in the future, when I get some new investments to my project