Add /Remove data between two datatables

Add /Remove data between two datatables

vishal1vishal1 Posts: 4Questions: 0Answers: 0
edited June 2011 in General

Hi,

I am trying to Add/ Remove data between two datatables, but i am getting an error.
Please find the code snippet in below:

I am getting following below error, when i try to add data from one datatable to another datatable.

" Datatables warning (table id='destination'): Requested unknown parameter '0' from the data source for row 0".

Please help me out.

Thanks,
Vishal

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    [code]

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">





    DataTables example

    @import "../../media/css/demo_page.css";
    @import "../../media/css/demo_table.css";




    var oTable;
    var giRedraw = false;

    $(document).ready(function() {
    /* Add a click handler to the rows - this could be used as a callback */
    $("#source tbody").click(function(event) {
    $(oTableSource.fnSettings().aoData).each(function (){
    $(this.nTr).removeClass('row_selected');
    });
    $(event.target.parentNode).addClass('row_selected');
    });

    /* Add a click handler for the delete row */
    $('#add').click( function() {
    var anSelected = fnGetSelected(oTableSource);
    oTableDest.fnAddData(anSelected[0]);
    } );

    /* Init the table */
    oTableSource = $('#source').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});
    oTableDest = $('#destination').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});

    } );


    /* Get the rows which are currently selected */
    function fnGetSelected( oTableLocal )
    {
    var aReturn = new Array();
    var aTrs = oTableLocal.fnGetNodes();

    for ( var i=0 ; i>
    Removed>>




    Rendering engine







    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hi Vishal,

    Looks like the forum totally butchered your post... I've just made some changes and reposted your code to get the correct formatting.

    I suspect that this is bit that is causing a problem:

    [code]
    var anSelected = fnGetSelected(oTableSource);
    oTableDest.fnAddData(anSelected[0]);
    [/code]
    It looks to me that you are trying to add a node to the new table by using fnAddData. However as the documentation for fnAddData notes, it expects an array (or object) of data - not a node. If you want to use a node then you can use this plug-in: http://datatables.net/plug-ins/api#fnAddTr .

    Allan
  • vishal1vishal1 Posts: 4Questions: 0Answers: 0
    Hi Allan,

    I modified the code, but now it is giving me following error:

    "Object does support this property or method".

    [code]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">;





    DataTables example

    @import "../../media/css/demo_page.css";
    @import "../../media/css/demo_table.css";




    var oTable;
    var giRedraw = false;

    $(document).ready(function() {
    /* Add a click handler to the rows - this could be used as a callback */
    $("#source tbody").click(function(event) {
    $(oTableSource.fnSettings().aoData).each(function (){
    $(this.nTr).removeClass('row_selected');
    });
    $(event.target.parentNode).addClass('row_selected');
    });

    /* Add a click handler for the delete row */
    $('#add').click( function() {
    var row = fnGetSelected(oTableSource);
    oTableDest.fnAddTr(row);
    } );

    /* Init the table */
    oTableSource = $('#source').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});
    oTableDest = $('#destination').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});

    } );


    /* Get the rows which are currently selected */
    function fnGetSelected( oTableLocal )
    {
    var row;
    var aTrs = oTableLocal.fnGetNodes();

    for ( var i=0 ; i>
    Removed>>




    Rendering engine







    [/code]


    Please help in this regards.

    Regards,
    Vishal






    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Where is it giving you that error?
  • vishal1vishal1 Posts: 4Questions: 0Answers: 0
    It is giving error at line 30 [oTableDest.fnAddTr(row); ]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    It doesn't look like you've included the fnAddTr plug-in code - which would probably result in that error. Here is an example of how plug-in API methods can be added: http://datatables.net/release-datatables/examples/plug-ins/plugin_api.html

    Allan
  • AntonioJuniorAntonioJunior Posts: 2Questions: 0Answers: 0
    Allan, do you have an example?
This discussion has been closed.