mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Math: Add "data-math-target" attribute
This commit is contained in:
parent
008b1e544a
commit
83b38fd419
2
dist/js/widgets/widget-math.min.js
vendored
2
dist/js/widgets/widget-math.min.js
vendored
File diff suppressed because one or more lines are too long
@ -196,6 +196,12 @@
|
|||||||
<h3><a href="#">Notes</a></h3>
|
<h3><a href="#">Notes</a></h3>
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>In <span class="version">v2.27.0</span>
|
||||||
|
<ul>
|
||||||
|
<li>Added check for <code>data-math-target</code> attribute which allows you to target an element inside the table cell. See the <a href="#attribute_settings">Attribute Settings</a> > <strong>Targeting cell content</strong> section below.</li>
|
||||||
|
<li>The math widget no longer uses "update" after recalculating cell values. Instead it uses "updateCache" to remove the need to resort and update the other widgets.</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<li>In <span class="version">v2.25.0</span>
|
<li>In <span class="version">v2.25.0</span>
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>math_rowFilter</code> can now be overridden by the row's <code>data-math-filter</code> attribute.</li>
|
<li><code>math_rowFilter</code> can now be overridden by the row's <code>data-math-filter</code> attribute.</li>
|
||||||
@ -576,6 +582,19 @@ $.tablesorter.equations['product'] = function(arry, config) {
|
|||||||
<pre class="prettyprint lang-js">math_ignore : [0,1]</pre>
|
<pre class="prettyprint lang-js">math_ignore : [0,1]</pre>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<h4>Targeting cell content</h4>
|
||||||
|
<ul>
|
||||||
|
<li>Version <span class="version">2.27.0</span> added a new data-attribute. The <code>data-math-target</code> attribute value must contain an element selector within the same cell.
|
||||||
|
<pre class="prettyprint lang-html"><tr>
|
||||||
|
<td data-math="sum-above" data-math-target=".sum">The total value is <span class="sum"></span></td>
|
||||||
|
</tr></pre>
|
||||||
|
</li>
|
||||||
|
<li>If you're using the grouping widget and want to sum up the value of the group, you'll need to also include a <code>data-column</code> attribute to target the table column to sum. Here is a <a href="https://jsfiddle.net/Mottie/st2p6uvs/">JSFiddle</a> demonstrating how to combine the two widgets.
|
||||||
|
<pre class="prettyprint lang-html"><tr>
|
||||||
|
<td colspan="5" data-math="sum-above" data-math-target=".sum" data-column="3">The total value is <span class="sum"></span></td>
|
||||||
|
</tr></pre>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3><a href="#">Mask Examples</a></h3>
|
<h3><a href="#">Mask Examples</a></h3>
|
||||||
|
@ -232,7 +232,6 @@
|
|||||||
mathAttr = wo.math_dataAttrib;
|
mathAttr = wo.math_dataAttrib;
|
||||||
$mathCells = c.$tbodies.children( 'tr' ).children( '[' + mathAttr + ']' );
|
$mathCells = c.$tbodies.children( 'tr' ).children( '[' + mathAttr + ']' );
|
||||||
changed = math.mathType( c, $mathCells, wo.math_priority ) || changed;
|
changed = math.mathType( c, $mathCells, wo.math_priority ) || changed;
|
||||||
|
|
||||||
// only info tbody cells
|
// only info tbody cells
|
||||||
$mathCells = c.$table
|
$mathCells = c.$table
|
||||||
.children( '.' + c.cssInfoBlock + ', tfoot' )
|
.children( '.' + c.cssInfoBlock + ', tfoot' )
|
||||||
@ -258,11 +257,11 @@
|
|||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
wo.math_isUpdating = true;
|
wo.math_isUpdating = true;
|
||||||
if ( c.debug ) {
|
if ( c.debug ) {
|
||||||
console[ console.group ? 'group' : 'log' ]( 'Math widget triggering an update after recalculation' );
|
console[ console.group ? 'group' : 'log' ]( 'Math widget updating the cache after recalculation' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// update internal cache
|
// update internal cache, but ignore "remove-me" rows and do not resort
|
||||||
ts.update( c, undef, function(){
|
ts.updateCache( c, function() {
|
||||||
math.updateComplete( c );
|
math.updateComplete( c );
|
||||||
if ( !init && typeof wo.math_completed === 'function' ) {
|
if ( !init && typeof wo.math_completed === 'function' ) {
|
||||||
wo.math_completed( c );
|
wo.math_completed( c );
|
||||||
@ -350,7 +349,14 @@
|
|||||||
changed = false,
|
changed = false,
|
||||||
prev = $cell.html(),
|
prev = $cell.html(),
|
||||||
mask = $cell.attr( 'data-' + wo.math_data + '-mask' ) || wo.math_mask,
|
mask = $cell.attr( 'data-' + wo.math_data + '-mask' ) || wo.math_mask,
|
||||||
|
target = $cell.attr( 'data-' + wo.math_data + '-target' ) || '',
|
||||||
result = ts.formatMask( mask, value, wo.math_wrapPrefix, wo.math_wrapSuffix );
|
result = ts.formatMask( mask, value, wo.math_wrapPrefix, wo.math_wrapSuffix );
|
||||||
|
if (target) {
|
||||||
|
$el = $cell.find(target);
|
||||||
|
if ($el.length) {
|
||||||
|
$cell = $el;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( typeof wo.math_complete === 'function' ) {
|
if ( typeof wo.math_complete === 'function' ) {
|
||||||
result = wo.math_complete( $cell, wo, result, value, arry );
|
result = wo.math_complete( $cell, wo, result, value, arry );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user