DataTables / RowReorder

Row reordering extensions for DataTables
Other
22 stars 27 forks source link

Reorder on Sort enhancement #2

Open MuellerMatthew opened 9 years ago

MuellerMatthew commented 9 years ago

In the following example: http://www.datatables.net/extensions/rowreorder/examples/initialisation/simple.html when a user sorts data on the table it does not alter the sequence numbers, so a user cannot use the sorts to reset the sequence numbers before customizing the sequence orders, so if a users has a particular sequence order right now they have to manually drag each item on the list into the right sequence.

Instead I think that when a user sorts the data by any of the columns other than the first column, there should be a setting to update the Seq. numbers with the newly sorted order. 'reorderOnSort: true or false' so that if i sort by names, then the first number in the sequence would be 'Airi Satou', and the sort numbers would proceed in alphabetical order. If the new option is 'true', the table will create a event listener on sorting, or perhaps the fnDrawCallback, and then after a table has changed, it updates the sequence numbers to whatever new position they are in the table.

Secondly, when a row is manually reordered by a users, the sort should automatically be removed from whichever column has it, and if the Seq. column is visible, it will indicate that the rows are now sorted by the Seq. column. Thus if the table is sorted by names, and then I drag a name to a different spot on the list, with the 'reorderOnSort' as true, the sort indicator would switch to the seq. list when it updates the positions since the list is no longer sorted by names.

DataTables commented 9 years ago

Thanks for your thoughts on this. The data swap that RowReorder uses when the data is rows are reordered is fairly core to the software. You can tell it to use any data property in the table, although a sequence number is the most common. Perhaps there should be an option to have it not update any data property, but I don't see the benefit of that, since the ordering applied to the DataTable would just move your row back to where it should be in the table ordering. It would only be useful if sorting were disabled, but then you'd still want to update a data property (even if it is a hidden column).

MuellerMatthew commented 9 years ago

Essentially, it would just add an event listener on the table sorting, so that whenever a table is sorted by a different column it would reset the sequence number of each row to whatever new row number the data is in the table. Then if a user manually drags a row, it sets the sort to the sequence column, and does the normal row reorder data swap.

DataTables commented 9 years ago

Oh I see. This example combined with the ability added to RowReorder to not update data would do what you are looking for then.

MuellerMatthew commented 9 years ago

Yes. Essentially I want a user to be able to use the sorting of the table as a jumping off point so they can customize their list faster without having to drag every item to where they want. I will have a pull request shortly to add the option.