On row click to fill another table with data?

On row click to fill another table with data?

darthvandarthvan Posts: 9Questions: 0Answers: 0
edited May 2010 in General
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.

Replies

  • darthvandarthvan Posts: 9Questions: 0Answers: 0
    Can someone help me with this please,even when just try to clear table with 0 parametar,table won't clear.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    So what you want to do is base the new content of table B on whatever was clicked in table A - right? In which case, you need to clear table B as you indicate, change sAjaxSource for the table, and then draw the table again.

    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
  • darthvandarthvan Posts: 9Questions: 0Answers: 0
    Problem was next ajax source didnt change on redraw,I solve it this way,before redraw i put this :

    [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.
This discussion has been closed.