In the example for percentages it will do the math over the entire table or only the current page.
http://datatables.net/examples/advanced_init/footer_callback.html
Great question :-). There are a lot of ways of doing this, and ultimately I want to build a plug-in to do it, but your prompt has inspired me to make a couple of small modifications to DataTables 1.9 - in particular the underscore function ( http://datatables.net/docs/DataTables/1.9.beta.3/#_ ). The underscore function will get data from the table based on the selector, however it did only do it for TR elements. I've just modified it a bit to allow TD/TH elements as well, so what you can now do is something as simple as:
That will give you an array of data from the 4th column which you can sum as you would do any other array :-)
The underscore function has a second argument which might prove useful as well so you can do things such as:
[code]
$('#example').dataTable()._('td:nth-child(4)', {"page": "current"}) // get the data from the current page only
$('#example').dataTable()._('td:nth-child(4)', {"filter": "applied"}) // get the data from all pages, but only the filtered data
[/code]
The ideal of the _ and $ functions in 1.9 is to make working with data and nodes much easier for exactly this kind of manipulation :-).
Replies
Any progress with this?
[code]
$('#example').dataTable()._('td:nth-child(4)')
[/code]
That will give you an array of data from the 4th column which you can sum as you would do any other array :-)
The underscore function has a second argument which might prove useful as well so you can do things such as:
[code]
$('#example').dataTable()._('td:nth-child(4)', {"page": "current"}) // get the data from the current page only
$('#example').dataTable()._('td:nth-child(4)', {"filter": "applied"}) // get the data from all pages, but only the filtered data
[/code]
The ideal of the _ and $ functions in 1.9 is to make working with data and nodes much easier for exactly this kind of manipulation :-).
Allan