fnGetData - Why is row 1 other than the following rows ????

fnGetData - Why is row 1 other than the following rows ????

AsterixAsterix Posts: 4Questions: 0Answers: 0
edited September 2012 in DataTables 1.9
Hi,
I've one problem:
if I do this:

$($('#example').dataTable().fnGetNodes()).each(function(i){
sData[i] = oTable.fnGetData(i);
console.log(JSON.stringify(oTable.fnGetData(i)));
});

I get this in firebug:

{"DT_RowId":"row_1","DT_RowClass":"","0":"1","1":"","2":"","3":"","4":"","5":"","6":"","7":""}
[2,"","","","","","",""]
[3,"","","","","","",""]
[4,"","","","","","",""]
[5,"","","","","","",""]

My question is: why is row 1 other than the row 2 to 5 ?
Is there a bug in fnGetData or do I something wrong ?

I need the function topost data as Json to a php-script.

Thanks and regards
Asterix

Replies

  • AsterixAsterix Posts: 4Questions: 0Answers: 0
    Hello,

    I found one thing: for row 0 I'll get back an object, the following rows are strings.
    How can I do it to get back ervery time an object ?

    Thanks.

    Best regards
    Asterix
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Can you give us a link to the page please? It looks to me that you are giving the first row as an object while the others are arrays (read from the DOM?).

    Allan
  • AsterixAsterix Posts: 4Questions: 0Answers: 0
    Hello Allan,

    to give you al ink is difficult, because the DataGrid ist running on an intern server, but I can give/post you the code (when my vm-box is running again).

    The first row is postet from a php and the following row are inserted by the fnAddData with this function:

    [code]
    function fnClickAddRow() {
    //console.log(this);
    var oSettings = $('#example').dataTable().fnSettings();
    var aiNew =$('#example').dataTable().fnAddData(["", "", "", "", "", "", "",""]); //insert empty row
    var nNewTr = oSettings.aoData[ aiNew[0] ].nTr;
    var row =aiNew[0] + 1;
    $('#example').dataTable().fnUpdate( oSettings.aoData.length, aiNew[0], 0 );
    $(nNewTr).attr('id', 'row_'+row); // set TR id
    }
    [/code]

    And this is the definition of the datatables:

    [code]
    /* Init DataTables */
    oTable = $('#example').dataTable({
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": false,
    "bInfo": false,
    "bAutoWidth": false,
    "bProcessing": false,
    "bServerSide": false,
    "sServerMethod": "POST",
    "sAjaxSource": "post-paramlist-dt.php",
    "fnServerParams": function ( aoData ) {
    aoData.push( { "name": "lparid", "value": "13" } );
    } ,
    "fnDrawCallback": function () {

    $('#example tbody td').editable(
    // callback
    function(value, settings) {
    // hier reihe anzeigen und zurückliefern
    console.log(this);
    console.log(value);
    console.log(settings);
    return(value); }
    , {
    "callback": function( sValue, y ) {
    // Redraw the table from the new data on the server
    oTable.fnDraw();
    },
    "height": "14px"
    } );
    },
    "aoColumnDefs": [ {
    "sClass": "center",
    "aTargets": [ -1, -2 ]
    } ],
    "aoColumns": [
    null,//{ "bVisible": 0 }, /* ID column */
    null,
    null,
    null,
    null,
    null,
    null,
    null
    ]
    } );
    [/code]

    So, if I understand you correct, I make a mistake at the adding of new rows?

    Thanks and best regards
    Asterix

    Regards
    Asterix
This discussion has been closed.