Solution
Reading comments on the project page I found modified source code of the plug-in by legrand….@gmail.com that fixes compatibility issues with DataTables 1.10.
Using that source code as a start I forked the add-on on github and added support for DataTables 1.10.
Demo
# | Name | Position | Office | Extn. | Start date | Salary |
---|---|---|---|---|---|---|
Name | Position | Office | Extn. | Start date | Salary |
$(document).ready(function(){
var table = $('#example').DataTable({
'ajax': {
'url': '/lab/articles/jquery-datatables-row-reordering/ids-arrays.txt'
},
'createdRow': function(row, data, dataIndex){
$(row).attr('id', 'row-' + dataIndex);
}
});
table.rowReordering();
});
In addition to the above code, the following Javascript library files are loaded for use in this example:
//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js
//code.jquery.com/ui/1.11.4/jquery-ui.min.js
//mpryvkin.github.io/jquery-datatables-row-reordering/1.2.2/jquery.dataTables.rowReordering.js
The following CSS library files are loaded for use in this example to provide the styling of the table:
//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.cssUsage
Table structure
- Table must be properly formatted according to the DataTables requirements e.g. it must have
THEAD
,TBODY
and optionallyTFOOT
sections - Each
TR
element must haveid
attribute. - One column in the table should be indexing column.
Limitations
- Rows can be ordered only by indexing column. This plugin will force ascending sorting by indexing column.
- Sorting by columns will be disabled. If you shuffle rows in some order other than indexing column order there will be no way to determine to what position row is dropped.
Notes
Allan Jardine, creator of DataTables, is working on a new RowReorder plug-in for upcoming release of DataTables 1.10.8. Once DataTables 1.10.8 and RowReorder plug-in are out, I will write an article about it and will recommend using it instead of the plug-in mentioned in this article.
Thanks for this plugin port.
I followed your fiddle and this tutorial but while I can drag rows of the table, the items return back to their original place as soon as mouse is released.
Here’s my table initialization:
Any reason why this could be ?
I am using the same CDN as you have used in the jsFiddle for DataTables and jQuery UI. I just didn’t understand what you mean when you say that “One column in the table should be indexing column.”
I see your table has a numbering column as the first column where as mine doesn’t have. So does that matter?
Yes, one columns should contain row indexes in sequential order: 1, 2, 3, etc. Row reordering plug-in relies on that data to correctly re-order rows.
Hi Michael, I have also followed your post. And, I encountered the same result while I drag a row item, the item returns back to the original place. I have set one of the columns as the row index in sequential order, but still the item returned back to the original location.
This is my script
I even used the exact version of .js and .css libraries mentioned in your post.
What could have been missing in my DataTable initialization?
Did anyone managed to find a solution for this ? I have the same problem, with an indexed column still doesn’t work 🙁
HTML dynamic table using JavaScript. How can I find the each row data , when we click on check box?
change “ordering”: false, to “ordering”: true
Hi,
Do u have any angular version?