Cannot reset the content of the table!

Cannot reset the content of the table!

koDkoD Posts: 3Questions: 0Answers: 0
edited October 2010 in General
Hello everybody.

I have some troubles with Datatables.
I'm using it to display in a modal popup a validation results of an import.
The first time, I don't have any kind of problems. But when I close the modal popup, upload a new file and get the new validation results, the old results are still here!

And I use the "bDestruy" argument.

So,please, check my code:

[code]
var obj = $.parseJSON(response);
var $contentTable = $('#failImport tbody');
// Reset the value
$contentTable.html('');
for (var i = 0; i < obj.length; i++) {
var $tr = $('').append($('').append(obj[i].game));
$tr.append($('').append(obj[i].ip));

var $ulError = $('');
for (var label in obj[i].errors) {
$ulError.append($('').append(obj[i].errors[label]));
}
$tr.append($('').append($ulError));
$contentTable.append($tr);
}

var oTable = $('#failImport').dataTable( {
"bDestroy" : true,
"bRetrieve": false,
"aaSorting": [[ 0, "asc" ],[ 1, "asc" ]],
"sPaginationType": "full_numbers",
"bSortClasses": false,
"bLengthChange": false,
"oLanguage": {
"sUrl": "/showTime-tournament/datatable/translation.txt"
}
});
$( oTable.fnGetNodes() ).colorbox({
inline : true,
href : '#uploadResult',
open : true,
scrolling : true,
transition : 'elastic',
overlayClose: false,
innerWidth : '60%',
innerHeight : '50%'
});
[/code]

And the HTML code

[code]





Error





[/code]

Thank you!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Try calling fnClearTable ( http://www.datatables.net/api#fnClearTable ) before initialising the table again (if it exists).

    Allan
  • koDkoD Posts: 3Questions: 0Answers: 0
    Hello.

    Ok so now the previous data are removed but the new one are not added!

    [code]if (!jQuery.isEmptyObject( oTable )) {
    oTable.fnClearTable();
    }
    oTable = $('#failImport').dataTable( {
    "bDestroy" : true,
    "bRetrieve": false,
    "aaSorting": [[ 0, "asc" ],[ 1, "asc" ]],
    "sPaginationType": "full_numbers",
    "bSortClasses": false,
    "bLengthChange": false,
    "oLanguage": {
    "sUrl": "/showTime-tournament/datatable/translation.txt"
    }
    });[/code]
  • koDkoD Posts: 3Questions: 0Answers: 0
    Well I have found the solution and I give you my code for a futur similar question

    [code]var obj = $.parseJSON(response);

    var importErrorsData = [];
    for (var i = 0; i < obj.length; i++) {
    importErrorsData[i] = [
    obj[i].game,
    obj[i].ip,
    "erreur"
    ];
    }
    if (!jQuery.isEmptyObject( oTable )) {
    oTable.fnClearTable();
    oTable.fnAddData( importErrorsData );
    } else {
    $('#uploadResult').html('');
    oTable = $('#importErrors').dataTable( {
    "aaData" : importErrorsData,
    "aoColumns" : [
    {"sTitle" : ''},
    {"sTitle" : ''},
    {"sTitle" : ''}
    ],
    "aaSorting": [[ 0, "asc" ],[ 1, "asc" ]],
    "sPaginationType": "full_numbers",
    "bSortClasses": false,
    "bLengthChange": false,
    "oLanguage": {
    "sUrl": "/showTime-tournament/datatable/translation.txt"
    }
    });
    }
    $( oTable.fnGetNodes() ).colorbox({
    inline : true,
    href : '#uploadResult',
    open : true,
    scrolling : true,
    transition : 'elastic',
    overlayClose: false,
    innerWidth : '60%',
    innerHeight : '50%'
    });[/code]

    I'm using the loading with Javascript array (but it's not necessary).

    Thank you for your help allan!
This discussion has been closed.