I am using a datatable jquery plugin on my site. Everything works well.
However, I am trying to improve the table using a script column filter, and then I want to summarize the data in the footer. I can make the filter work correctly.
The example in datatables for summing data works only on the data page or the entire data set.
I found this thread: http://datatables.net/forums/discussion/2053/fnfootercallback-sum-column-after-filter/p1 is looking for a similar solution. The author offers the following function:
._('td:nth-child(4)', {"filter": "applied"})
This obviously returns a filtered data object. However, as soon as I have it, I don’t know where to start adding data
At the moment, my datatable script (short for message) is as follows:
table.dataTable({... "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) { var iTotalSales = 0; for ( var i=0 ; i<aaData.length ; i++ ) { iTotalSales += aaData[i][2]*1; } var iPageSales = 0; for ( var i=iStart ; i<iEnd ; i++ ) { iPageSales += aaData[ aiDisplay[i] ][2]*1; } var secondRow = $(nRow).next()[0]; var nCells = secondRow.getElementsByTagName('td'); nCells[0].innerHTML = accounting.formatMoney(iPageSales, "£ ", 2) + ' Page Total ('+ accounting.formatMoney(iTotalSales, "£ ", 2) +' Total Sales)'; } }) .columnFilter({ aoColumns: [ { type: "date-range" }, null, { type: "text" }, { type: "text" }, { type: "select" }, { type: "select" } ] }) ._('td:nth-child(4)', {"filter": "applied"});
I currently have a summary, as shown above, that displays the total number of filters per page relative to the overall table (all data is not just filtered)
I'm a beginner jquery - I'm not sure where to start manipulating the object created in the last call
thanks