Moving rows up and down.

Moving rows up and down.

dennedenne Posts: 30Questions: 0Answers: 0
edited October 2010 in General
Im trying to add functionality to my datatable with buttons that:
* move row to the top of the table
* move row one position up in the table
* move row down one position in the table
* move row to the bottom of the table.

And im not sure about how to accomplish this with this datatable component.
I tried to manipulate the DOM directly with jQuery and managed to get the rows to move like I want, but as soon as the datatable has trigged a redraw event all changes to the datatable DOM is reset and redrawn from the datasource as it was in the original data. Does Datatable have any methods for manipulating the data it operates on like this, moving rows around?

Replies

  • ajoslin103ajoslin103 Posts: 20Questions: 4Answers: 0
    I made this (bubbleUp & bubbleDown) work by adding a sortOrder [hidden] column and then using fnUpdate to control the sortOrder values in aoData followed by looping aiMasterDisplay to index into aoData to get the items back in sorted order (looping with aiDisplay will return the filtered sorted set)
  • dennedenne Posts: 30Questions: 0Answers: 0
    I have made a brute force style approach now which seems to work with fnUpdate which moves values around the datatable. I dont have any paging, sorting or filtering enabled in my table.

    [code]
    function moveSelectedUp(){
    var arr = jQuery('#table tbody tr.selected_row')

    for(var i=0; i
  • dennedenne Posts: 30Questions: 0Answers: 0
    I found this, the last comment in the thread about how ordering is implemented in datatable when you dont use sorting: http://datatables.net/forums/comments.php?DiscussionID=235&page=1#Item_0

    I have reimplemented my code above to manipulate the order how aoData is drawn by manipulate fnSettings.aiDisplay instead of moving data around is aoData. Works very nicely. Not sure what to do when my users decides that they must have filtering and sorting.. :)
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Heh - very nice - thanks for posting your code.

    What I would suggest for integrating this with filtering and user sorting, is to consider using aaFixedSorting on a hidden column. This will allow you to force DataTables to always order by a given column (the hidden one) first, before doing the user ordering. In the hidden column have an index counter which will define the order you want.

    Allan
This discussion has been closed.