Create a master-detail table
Create a master-detail table
temerariomalaga
Posts: 16Questions: 0Answers: 0
I was looking the official manual of Datatables and I found that: http://www.datatables.net/release-datatables/examples/server_side/row_details.html
I'm trying to make a master-detail table like this but I want to show the detail in other table, not in the master table. I think that I can get the content of the row I click and send it using AJAX to do the query and show the content in the detail table. I have the following code for load the datatables and can click in a row.
[code]$(document).ready( function () {
$('#PRESUP').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );
$('#PRESUP_D').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );
} );[/code]
PRESUP is the master table and PRESUP_D is the detail table. I need to add to this function other function for get the value of the clicked row and for send it to an AJAX file.
I'm trying to make a master-detail table like this but I want to show the detail in other table, not in the master table. I think that I can get the content of the row I click and send it using AJAX to do the query and show the content in the detail table. I have the following code for load the datatables and can click in a row.
[code]$(document).ready( function () {
$('#PRESUP').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );
$('#PRESUP_D').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );
} );[/code]
PRESUP is the master table and PRESUP_D is the detail table. I need to add to this function other function for get the value of the clicked row and for send it to an AJAX file.
This discussion has been closed.
Replies
Allan
[code]$(document).ready( function () {
var oTable=$('#PRESUP').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );
oTable.$('tr').click( function () {
var data = oTable.fnGetData( this );
var serie=data[0];
var numero=data[1];
var nombre=data[3];
var vendedor=data[4];
$("#prueba1").val(serie);
$("#prueba2").val(numero);
$("#seriedel1").val(serie);
$("#numerodel1").val(numero);
$("#nombre1").val(nombre);
$("#vendedor1").val(vendedor);
load();
$("#eds").val(serie);
$("#edn").val(numero);
} );
var oTable2=$('#PRESUP_D').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single"
}
} );
oTable2.$('tr').click( function () {
var data = oTable.fnGetData( this );
} );
} );[/code]
Allan
Allan
http://www.asp.2asir.ieslosmanantiales.es/presup.php
Thank you for all Allan.
Allan
Its not working because you aren't using the DataTables API - you are overwriting and replacing the existing table and DataTables doesn't (and can't) know that you've done that...
Use fnAddData to add a new row to an existing table. Or `row.add()` in 1.10.
Allan
Allan