We have table sorter JS running and it works great, however the count function is counting all cells in the column not just those with data.
Is there a way to configure the count function to ignore empty cells?
The 3rd column should be 0 not 24
$(".sortableTable-totalsRow").tablesorter({
theme: "bootstrap",
widgets: ['filter', 'math'],
widgetOptions: {
math_data: 'math', // data-math attribute
math_ignore: [0, 1, ''],
math_textAttr: '',
math_none: 'N/A', // no matching math elements found (text added to cell)
math_complete: function ($cell, wo, result, value, array)
{
var textClass = $cell.attr('data-math-textAttr');
if (textClass == undefined)
{
textClass = "align-right";
}
var txt = '<span class="' + textClass + '" >' +
(value === wo.math_none ? '' : ' ') +
result + '</span>';
if ($cell.attr('data-math') === 'all-sum') {
// when the "all-sum" is processed, add a count to the end
return txt + ' (Sum of ' + array.length + ' cells)';
}
return txt;
},
math_completed: function (c) {
// called after all math calculations have completed
},
// cell data-attribute containing the math value to use (added v2.31.1)
// see "Mask Examples" section
math_mask: '##0.00',
math_prefix: '', // custom string added before the math_mask value (usually HTML)
math_suffix: '', // custom string added after the math_mask value
// event triggered on the table which makes the math widget update all data-math cells (default shown)
math_event: 'recalculate',
// math calculation priorities (default shown)... rows are first, then column above/below,
// then entire column, and lastly "all" which is not included because it should always be last
math_priority: ['above', 'below', 'col', 'row'],
// set row filter to limit which table rows are included in the calculation (v2.25.0)
// e.g. math_rowFilter : ':visible:not(.filtered)' (default behavior when math_rowFilter isn't set)
// or math_rowFilter : ':visible'; default is an empty string
math_rowFilter: ''
}
});
<tfoot class="sticky-bottom">
<tr style="border-top: double">
@for (int i = 0; i < (Model.Heading.Count() - 2); i++)
{
<th class="text-center" data-math="col-count" data-math-mask="#,###.00">col-count</th>
<th class="text-right" data-math="col-sum" data-math-mask="#,##0.00">col-sum</th>
}
</tr>
</tfoot>