How do I add a static custom footer (from json data) when creating the table?
How do I add a static custom footer (from json data) when creating the table?
Hi,
I want to add a custom footer to my table at initialization. The footer is static and all the values are precalculated by a php script and fetched by ajax before. What I'd like best is to simply throw an array at DataTables (like I do with my actual table data) to fill in two rows in the footer. However, I don't want to add any footer cells in html, everything needs to be a jQuery or DataTable function. Is there a way?
HTML
<table id="skills"><thead></thead><tfoot></tfoot></table>
JS
options = {
"data": stats_rows,
"columns": stats_cols,
"bPaginate": false,
"info": false
};
target = '#skills';
var table = $(target).addClass('display').DataTable(options);
My table will correctly show without pagination and info display, but will ONLY show the header and no footer at all (I thought the footer was a standard option).
Now I need a way to add two rows of data to the footer from my array stat_footrows.
Thank you all for your help and thanks to Allan for creating this wonderful plugin. It really excels where jQgrid and tablesorter fall short.
Answers
Is there a function that allows me to create a valid row from array data like
['value1','value2','value3','value4']
to
<tr><td>value1</td><td>value2</td><td>value3</td><td>value4</td></tr>
and add it to the footer or do I need to do this myself?
I wrote a function that basically did that, the function takes the element that it should tie the footer to (the same one that you're going to call the datatable on) and an array of columns (as you specified). It's important to note that you have to call the function before you initialize the table otherwise it wont be hooked up automatically.
The result would be an input for each value in the array that looks something like
Obviously you can remove all the specific attributes on the input as you see fit, I just wanted them for various reasons.