Moving rows up and down with datatables

Moving rows up and down with datatables

ronovarronovar Posts: 6Questions: 2Answers: 0

Hi,
i spend one week and could not get this datatables to work...what i try to get is when user click on UP or DOWN button on toolbar rows move up or down and renumber id in tr element so that i can later update my database with fresh id.I im building channel editor..so here is jsfiddle example with other example data inside table...i try this code but it is does not work..if some one can add code to jsfiddle and post here link i will be very thankful.

code that i have try:

$(document).on('click', '.moveup', function(e){
var index = $(this).attr('index');
if ((index-1) >= 0) {
var datatable = $('#datatable.table').dataTable()
var data = datatable.fnGetData();
datatable.fnClearTable();
data.splice((index-1), 0, data.splice(index,1)[0]);
datatable.fnAddData(data);
}
});
$(document).on('click', '.movedown', function(e){
var index = $(this).attr('index');
if ((index+1) >= 0) {
var datatable = $('#datatable.table').dataTable()
var data = datatable.fnGetData();
datatable.fnClearTable();
data.splice((index+1), 0, data.splice(index,1)[0]);
datatable.fnAddData(data);
}
});

it is not working..i im getting same input in table as original..no changes.

Here is jsfiddle link that needs to add functions to move rows up and down with id renumbering..i im using client side.

http://jsfiddle.net/ns1rr084/

Answers

  • ronovarronovar Posts: 6Questions: 2Answers: 0

    Anyone can help? I try to figure this out but i im unable to move rows up and down..please i need solution so that i can finish project.

    Thanks.

  • ronovarronovar Posts: 6Questions: 2Answers: 0

    Here is updated code for moving rows up and down(taken from this forum) but the code does not work...can some one have a clue where is the eroor?

    http://jsfiddle.net/ns1rr084/11/

  • ronovarronovar Posts: 6Questions: 2Answers: 0

    Here is updated code..i see in console log that data is shifted correctly but function fnAddData is displaying old data, does anyone know why?

    http://jsfiddle.net/ns1rr084/17/

This discussion has been closed.