Sunday 15 August 2010

jQuery Datatables - Sum Column with class in cell -


I am trying to submit several columns in the datatables.net table (column 5, 6, 7) so that the footer In the article, each of these columns shows the amount of that column

The issue is that one cell has many values ​​and in other cells a value is wrapped in a span tag. Therefore, the total is being shown in the form of Nain

Is the column declared not only a method to use the footer callback method to declare the class?

Or what would be the best way to sum up the columns (and show the current page amount and yoga on all pages - which is with the Patrickllback method)

I have many different - Have tried different things that include declaring variables, adding .cell ('.classname') and .cells (. 'Classname'), but does not return anything to the amount. It works fast to work properly If there is nothing other than the value in the cell, but in this case There is not an option for the RE table.

Here is the datatable code I am using:

  $ (document) .ready (function () {$ ('# example'). DataTable ({ "Footer callback": Remove formatting for function data (line, data, start, end, display) {var api = this.api (), data; // to get integer data for equation var intVal = function (i) { Return typeof I === 'string'? I.replace (/ [\ $,] / g, '') * 1: typeof i === 'number'? I: 0;}; // Overall, all pages Total = api.column (6) .data (). Reduce (function (a, b) {return intVal (a) + intVal (b);}); // Overall page page = total api.column ( 6, {pay : 'Current'}) .Date (.) Reduce (function (a, b) {return intVal (a) + integral (b);}, 0); // updated footer $ (Api.column (6). Footer ()). Html ('$' + page total + '($' + total + 'total)');}});  

}); `

The table code is quite complex so I have created a JSField:

you Reduce methods, there is a problem.

In your lower method, variable b is not number (money), instead it is a tag

$ < Span class = "addExpChangedClass AMTField payment criteria 1" data-sort = "1.00" & gt; 1.00 & lt; / Span & gt;

Step:

  1. I previously entered $ to b.replace ('$', ''

  2. Then the rest string was changed to a jQuery object so that the value (which is the amount) can be removed $ (B.

    Finally it looks like

      total = api.column ( 6) .Data (). Reduce (function (total, b) {b = $ (b.replace ('$', '')) .text (); return returned + parseInt (b);), 0); // Overall, page pages total = api.column (6, {page: 'current'}) .data (). Rayes (function ( Total, Parsiint (B);}, 0);  

    Updated

    Hope this will be helpful.


No comments:

Post a Comment