On row click to fill another table with data?
On row click to fill another table with data?
Hello,I'm new here,and just want to say that datatables are amazing.
My problem is next.I have one table-A table,and when click on row in A table want to fill another table-B table.Is this possible via ajax,not to reaload page?Whit ordinary table I do it easy,but with datatables I got warning "DataTables warning: Unable to re-initialise DataTable. Please use the API to make any configuration changes required" or just data dont reload in B-table.
I try something like this,but table dont refresh data.Here is my code :
[code]
$("#aTable tbody").click(function(event) {
$(oTableKat.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
var aData = oTableKat.fnGetData( fnGetSelected( oTableKat )[0] );
if (typeof(oTableSlike) == 'undefined') {
oTableSlike = $("#bTable").dataTable( {
"bServerSide": true,
"bProcessing": true,
"bJQueryUI": true,
"bLengthChange": false,
"bFilter": true,
"iDisplayLength": 8,
"sAjaxSource": "<?php echo $full_path_ajax_php.'?sta_radimo=2&idKat='; ?>"+aData[3],
"aaSorting": [[ 0, "asc" ],[ 3, "asc" ]],
"sDom": '<"top"ir>t<"bottom"pf<"clear">',
"sPaginationType": "full_numbers",
"oLanguage": {
"sUrl": "<?php echo $full_path_jezik_2;?>"
},
"aoColumns": [
{ "sName": "rb","sWidth": "15%", "sClass": "center","sType": "numeric" },
{ "sName": "chkZaBrisanje","sWidth": "20%", "sClass": "center", "bSortable":false },
{ "sName": "rbPrvaSlika","sWidth": "15%", "sClass": "center","bSortable":false },
{ "sName": "nazivSlike","sWidth": "50%", "sClass": "center", "sSortDataType": "dom-text" }
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.getJSON( sSource, aoData, function (json) {
/* nothing for now */
fnCallback(json)
} );
}
} );
}
else
{
oTableSlike.fnClearTable( 1 );
}
});
[/code]
Sorry on my bad English,and just one thing maybe my approach isnt good,that is because I'm not javascript or jquery programmer.Tnx in advance.
My problem is next.I have one table-A table,and when click on row in A table want to fill another table-B table.Is this possible via ajax,not to reaload page?Whit ordinary table I do it easy,but with datatables I got warning "DataTables warning: Unable to re-initialise DataTable. Please use the API to make any configuration changes required" or just data dont reload in B-table.
I try something like this,but table dont refresh data.Here is my code :
[code]
$("#aTable tbody").click(function(event) {
$(oTableKat.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
var aData = oTableKat.fnGetData( fnGetSelected( oTableKat )[0] );
if (typeof(oTableSlike) == 'undefined') {
oTableSlike = $("#bTable").dataTable( {
"bServerSide": true,
"bProcessing": true,
"bJQueryUI": true,
"bLengthChange": false,
"bFilter": true,
"iDisplayLength": 8,
"sAjaxSource": "<?php echo $full_path_ajax_php.'?sta_radimo=2&idKat='; ?>"+aData[3],
"aaSorting": [[ 0, "asc" ],[ 3, "asc" ]],
"sDom": '<"top"ir>t<"bottom"pf<"clear">',
"sPaginationType": "full_numbers",
"oLanguage": {
"sUrl": "<?php echo $full_path_jezik_2;?>"
},
"aoColumns": [
{ "sName": "rb","sWidth": "15%", "sClass": "center","sType": "numeric" },
{ "sName": "chkZaBrisanje","sWidth": "20%", "sClass": "center", "bSortable":false },
{ "sName": "rbPrvaSlika","sWidth": "15%", "sClass": "center","bSortable":false },
{ "sName": "nazivSlike","sWidth": "50%", "sClass": "center", "sSortDataType": "dom-text" }
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.getJSON( sSource, aoData, function (json) {
/* nothing for now */
fnCallback(json)
} );
}
} );
}
else
{
oTableSlike.fnClearTable( 1 );
}
});
[/code]
Sorry on my bad English,and just one thing maybe my approach isnt good,that is because I'm not javascript or jquery programmer.Tnx in advance.
This discussion has been closed.
Replies
An alternative might be to use the 'destroy' option in the new DataTables 1.7 beta. If you include bDestroy:true in the initialisation object, and DataTables finds that a table already exists for the target, then it will destroy the old table and create a new one. A bit more brutal, but should be effective.
Allan
[code]
var oSettings = oTableSlike.fnSettings();
oSettings.sAjaxSource = "my new ajax source";
[/code]
Tnx Allan on response,I will look new 1.7 beta.
Thank you on datatables.Great work.