Moving items from datatable 1 to datatable 2

Moving items from datatable 1 to datatable 2

luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
edited January 2014 in Editor
Hi Guys,

I just need some basic directions on how to implement this...

I have a page with two side by side datatables, I retrieve the data myself for both tables (no php on the back end)... there are 2 buttons between them (one pointing to left, another to right).. The intention is to have the customer select multiple lines from either table, press a button and have the software move them across table.


Tks,
Luis

Replies

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Sounds like you want to use the fnDeleteRow and fnAddData API methods. Simply get the data for each row you want to delete (using fnGetData ), then delete them from the old table and add them to the new table :-)

    Allan
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    cool, how do I detect the selected items on a table?
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    What software are you using to select the rows? If TableTools then the fnGetSelected method - http://datatables.net/extras/tabletools/api#fnGetSelected

    Allan
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    That worked perfectly! Tks


    [code]

    function BackLogLeftClick(){
    var oTT = TableTools.fnGetInstance( 'HomeBacklog2' );
    var SelItems = oTT.fnGetSelected();
    if (SelItems.length > 0) {

    //retreive item list
    var itemlist = [];
    var SelItemsData = oTT.fnGetSelectedData();
    for (item in SelItemsData){
    itemlist.push(SelItemsData[item].id );
    };

    //post to server...
    $.post( "Data.php?tbl=12", { action: 'sprint', items: itemlist, sprint: "" })
    .fail(function(xhr, textStatus, errorThrown) {
    alert(xhr.responseText);
    })
    .done(function( data ) {
    // alert( "Data Loaded: " + data );
    // remove items from left table
    for (item in SelItems){
    HomeBacklog2T.fnDeleteRow(SelItems[item],null, false);
    };

    // add items to second table
    HomeBacklogT.fnAddData(SelItemsData);

    // force redraw on left table (since false was passed to fnDeleteRow...)
    HomeBacklog2T.fnDraw();
    });
    }

    return false;
    }

    [/code]
This discussion has been closed.