footerCallback on a of a child table
footerCallback on a of a child table
jalape
Posts: 117Questions: 2Answers: 1
in TableTools
Good afternoon,
I have a child table built from a function:
function createChild ( row ) {
var table = $('<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tfoot>'+
'<tr>'+
'<th colspan="4" style="text-align:right">'+
'Suma:'+
'</th>'+
'</tr>'+
'</tfoot>'+
'</table>');
row.child( table ).show();
...
The fields are mounted from the columns:
columns: [
{ title: 'Tipo', data: 'tb_objeto.objeto' },
{ title: 'Item', data: 'tb_item.item' }
…
To fill the Sum of the <tfoot> I use a "footerCallback": function
The question is: How can I pass the data from the footerCallback to the <tfoot>
Thank you.
This discussion has been closed.
Replies
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Sorry, I didn't think it was necessary this time. The path is: http://javierlasen.es/easd/login/admin_nota.php.
The secondary table is displayed by clicking on any record in the "Sec" field of the main table.
In the secondary table, “Suma” would have to calculate the sum of all the records in the “Media” field.
To have data in the secondary table, write in the Search of the main table, the value 1348.
Thank you
Hi,
The best way to write into a footer element is with the
column().footer()
method as shown in this example.Allan
Thanks Allan for answering,
I have put it following the example, the problem is that I don't know how to pass the sum data to the footer of the secondary table.
I have tried it this way:
The problem is you are trying to use the summation variables when crating your
tfoot
, ie, line 9 in the above code. Structure your footer like the example Allan linked to. Click on the HTML tab and scroll to the bottom to see the footer. Line 120 will take care of populating the footer with the sum value.Kevin
Thanks kthorngren for replying,
But in my case the html file only has the main table, the secondary table is created with the variable "table" in line 3. From the datatable_nota.js file of the previous comment, and fill the fields with the "columns" of the line 60.
This is the html of the main file admin_nota.php
Yes, I understand. The -tag tfoot
is created in that function and is part of the
-tag table` assigned to the child table. Did you try my recommendation? You want something like this:Kevin
'<th></th>'+
Sometimes something so simple and not seen. Thank you very much for your time.
Happens to me all the time
That reassures me.
One last thing, is this way of displaying the child table compatible with:
responsive: true,
http://www.javierlasen.es/easd/login/admin_nota.php
Yes - you can use a modal instead for a child row (or anything else if you want to write a plug-in for Responsive to display the data somewhere else!).
Allan
But the modal would not allow me to query two child tables at the same time.
I've been trying to change the event that shows and hides the child table:
By a method that I have found with the intention that when pressing the responsive button, both the hidden fields of the main table and the secondary table are shown. Perhaps this is not possible.
The reference example is: https://datatables.net/reference/event/responsive-display
This is the code that Responsive uses to display a child row.
If you want it to be displayed in something other than a modal or a child row, you'd be best to add to the
$.fn.dataTable.Responsive.display
object, like that code does, then you can enable your plug-in with theresponsive.details.display
option.See also the docs here for more about how Responsive displays the otherwise hidden information.
Allan
The only way to display the child table is by using: Responsive.display.modal(). But this way I can't have two child tables open at the same time.
With: Responsive.display.childRowImmediate, it just shows me the hidden fields from the main table. It's like allocating the space for responsive behavior and removing the rest. I can't get the child table below.
Correct - if you want to use a child row for something else, then you can't also use it for Responsive. You need to use some other display technique for Responsive, such as the modal.
Allan
I will see how I can solve this problem. If I get something I will get it.
Thank you Allan