Cannot reset the content of the table!
Cannot reset the content of the table!
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!
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!
This discussion has been closed.
Replies
Allan
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]
[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!