Skip to content

data-math="ignore" is not ignored (Math Widget) #1526

Closed
@JamoCA

Description

@JamoCA

I'm generating a table with numeric values, but some records don't have any data. In this case, I'm not outputting any value and the TD element is empty. I noticed that the math widget was converting these empty values to "0" when averaging, so I added data-math="ignore" to these empty TD elements. The cells are still being converted to "0" and included in the average.

For example, the mean of non-ignored fields should be "100". The value "60" is returned, so this must mean that it's evaluating ignored cells as "0" instead of ignoring them. (By comparison, if I create 5 cells in Excel and only 3 are populated w/100, the average is "100".)

<script>
$(function(){
	$('#mathTable').tablesorter({
		widgets: ['math'],
		widgetOptions : {
			math_debug: true
		}
	});
});
</script>

<table id="mathTable" class="tablesorter-blue">
<thead>
	<tr><th>ID</th><th>Value</th></tr>
</thead>
<tfoot>
<tr>
	<th data-math="col-count"></th>
	<th data-math="col-mean"></th>
</tr>
</tfoot>
<tbody>
	<tr><td>1</td><td>100</td></tr>
	<tr><td>2</td><td>100</td></tr>
	<tr><td>3</td><td>100</td></tr>
	<tr><td>4</td><td data-math="ignore"></td></tr>
	<tr><td>5</td><td data-math="ignore"></td></tr>
</tbody>
</table>

The console outputs:

col-count  (5) [0, 1, 2, 3, 4] = 5
widget-math.min.js:2 col-mean  (5) [100, 100, 100, 0, 0] = 60

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions