I am needing to sum the "Total" column. I would like to add the result to the footer of the table.
<script>
$(document).ready(function () {
$("#orderTable").DataTable(
{
"ajax": {
"url": "/Orders/GetList",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "CustomerName" },
{ "data": "OrderDate" },
{ "data": "Total" },
]
});
});
</script>
Any guidance is appreciated.
3
Answers
For anyone else searching for a solution:
ref: Jquery DataTable column Sum (Good structural reference in second answer)
ref: https://www.ihbc.org.uk/consultationsdb_new/examples/advanced_init/footer_callback.html
There is option called
drawCallback
, use that like below.And HTML for total:
Via CSS place your
div
where ever you want.I think so best thing to do is getting sum directly from the server something like ("/Orders/GetTotal")
You can handle GetTotal And GetList together to prevent double request to database