Math: Add "data-math-target" attribute

This commit is contained in:
Rob Garrison 2016-07-13 20:30:32 -05:00
parent 008b1e544a
commit 83b38fd419
No known key found for this signature in database
GPG Key ID: 0A42D160D71978E1
3 changed files with 30 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -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> &gt; <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">&lt;tr&gt;
&lt;td data-math=&quot;sum-above&quot; data-math-target=&quot;.sum&quot;&gt;The total value is &lt;span class=&quot;sum&quot;&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;</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">&lt;tr&gt;
&lt;td colspan=&quot;5&quot; data-math=&quot;sum-above&quot; data-math-target=&quot;.sum&quot; data-column=&quot;3&quot;&gt;The total value is &lt;span class=&quot;sum&quot;&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;</pre>
</li>
</ul>
</div> </div>
<h3><a href="#">Mask Examples</a></h3> <h3><a href="#">Mask Examples</a></h3>

View File

@ -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 );
} }