mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Parser: add checkbox parser class name ("checkboxClass") option
This commit is contained in:
parent
95cf3f8044
commit
13a035cad0
2
dist/js/parsers/parser-input-select.min.js
vendored
2
dist/js/parsers/parser-input-select.min.js
vendored
@ -1,2 +1,2 @@
|
||||
/*! Parser: input & select - updated 5/17/2015 (v2.22.0) */
|
||||
!function(a){"use strict";var b=function(a,b,c){};a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"inputs-numeric",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input"),f=e.length?e.val():b,g=a.tablesorter.formatFloat((f||"").replace(/[^\w,. \-()]/g,""),c);return b&&"number"==typeof g?g:b?a.trim(b&&c.config.ignoreCase?b.toLocaleLowerCase():b):b},parsed:!0,type:"numeric"}),a.tablesorter.addParser({id:"checkbox",is:function(){return!1},format:function(b,c,d,e){var f=a(d),g=c.config.widgetOptions,h=g.group_checkbox?g.group_checkbox:["checked","unchecked"],i=f.find('input[type="checkbox"]'),j=i.length?i[0].checked:"";return f.closest("tr").toggleClass("checked checked-"+e,j),i.length?h[j?0:1]:b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select-text",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.find("option:selected").text()||"":b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"textarea",is:function(){return!1},format:function(b,c,d){var e=a(d).find("textarea");return e.length?e.val():b},parsed:!0,type:"text"}),a(function(){a("table").on("tablesorter-initialized updateComplete",function(){var c=".parser-forms",d=function(b){b&&a(":focus").blur()};a(this).children("tbody").off(c).on("mouseleave"+c,function(a){d("TBODY"===a.target.nodeName)}).on("focus"+c,"select, input, textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur"+c,"input, textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup ".split(" ").join(c+" "),"select, input, textarea",function(c){if(27===c.which)return void(this.value=a(this).data("ts-original-value"));if("change"===c.type||"keyup"===c.type&&13===c.which&&("INPUT"===c.target.nodeName||"TEXTAREA"===c.target.nodeName&&c.altKey)){var d,e=a(c.target),f=e.closest("td"),g=f.closest("table"),h=f[0].cellIndex,i=g[0].config||!1,j=i&&i.$headerIndexed&&i.$headerIndexed[h]||[],k=e.val();if(j.length&&(j.hasClass("parser-false")||j.hasClass("sorter-false")&&j.hasClass("filter-false")))return;(k!==e.data("ts-original-value")||"checkbox"===c.target.type)&&(e.data("ts-original-value",k),g.trigger("updateCell",[f,d,function(){b(c,g,e)}]))}})})})}(jQuery);
|
||||
!function(a){"use strict";var b=function(a,b,c){};a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"inputs-numeric",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input"),f=e.length?e.val():b,g=a.tablesorter.formatFloat((f||"").replace(/[^\w,. \-()]/g,""),c);return b&&"number"==typeof g?g:b?a.trim(b&&c.config.ignoreCase?b.toLocaleLowerCase():b):b},parsed:!0,type:"numeric"}),a.tablesorter.addParser({id:"checkbox",is:function(){return!1},format:function(b,c,d,e){var f=a(d),g=c.config.widgetOptions,h=c.config.checkboxClass||"checked",i=g.group_checkbox?g.group_checkbox:["checked","unchecked"],j=f.find('input[type="checkbox"]'),k=j.length?j[0].checked:"";return f.closest("tr").toggleClass(h+" "+h+"-"+e,k),j.length?i[k?0:1]:b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select-text",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.find("option:selected").text()||"":b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"textarea",is:function(){return!1},format:function(b,c,d){var e=a(d).find("textarea");return e.length?e.val():b},parsed:!0,type:"text"}),a(function(){a("table").on("tablesorter-initialized updateComplete",function(){var c=".parser-forms",d=function(b){b&&a(":focus").blur()};a(this).children("tbody").off(c).on("mouseleave"+c,function(a){d("TBODY"===a.target.nodeName)}).on("focus"+c,"select, input, textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur"+c,"input, textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup ".split(" ").join(c+" "),"select, input, textarea",function(c){if(27===c.which)return void(this.value=a(this).data("ts-original-value"));if("change"===c.type||"keyup"===c.type&&13===c.which&&("INPUT"===c.target.nodeName||"TEXTAREA"===c.target.nodeName&&c.altKey)){var d,e=a(c.target),f=e.closest("td"),g=f.closest("table"),h=f[0].cellIndex,i=g[0].config||!1,j=i&&i.$headerIndexed&&i.$headerIndexed[h]||[],k=e.val();if(j.length&&(j.hasClass("parser-false")||j.hasClass("sorter-false")&&j.hasClass("filter-false")))return;(k!==e.data("ts-original-value")||"checkbox"===c.target.type)&&(e.data("ts-original-value",k),g.trigger("updateCell",[f,d,function(){b(c,g,e)}]))}})})})}(jQuery);
|
@ -597,6 +597,20 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr id="checkboxclass">
|
||||
<td><a href="#" class="permalink">checkboxClass</a></td>
|
||||
<td>String</td>
|
||||
<td>"checked"</td>
|
||||
<td>Used by the "checkbox" parser in the <code>parser-input-select.js</code> file (<span class="version">v2.22.2</span>).
|
||||
<div class="collapsible">
|
||||
<p>When using the checkbox parser, this class name is added to the row along with this class name plus the column index when the targeted checkbox is checked.</p>
|
||||
<p>For example, if the named parser file has been loaded & "sorter-checkbox" class is added to the first column header, then any checked checkbox in the first column will have <code>"checked checked-0"</code> class names added to the row.</p>
|
||||
Checkboxes in any other column, not targeted by the parser, will be ignored and no extra row class names will be added.
|
||||
</div>
|
||||
</td>
|
||||
<td><a href="example-widget-output.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="cssasc">
|
||||
<td><a href="#" class="permalink">cssAsc</a></td>
|
||||
<td>String</td>
|
||||
|
@ -54,6 +54,7 @@
|
||||
format : function( txt, table, cell, cellIndex ) {
|
||||
var $cell = $( cell ),
|
||||
wo = table.config.widgetOptions,
|
||||
checkedClass = table.config.checkboxClass || 'checked',
|
||||
// returning plain language here because this is what is shown in the
|
||||
// group headers - change it as desired
|
||||
status = wo.group_checkbox ? wo.group_checkbox : [ 'checked', 'unchecked' ],
|
||||
@ -61,7 +62,7 @@
|
||||
isChecked = $input.length ? $input[ 0 ].checked : '';
|
||||
// adding class to row, indicating that a checkbox is checked; includes
|
||||
// a column index in case more than one checkbox happens to be in a row
|
||||
$cell.closest( 'tr' ).toggleClass( 'checked checked-' + cellIndex, isChecked );
|
||||
$cell.closest( 'tr' ).toggleClass( checkedClass + ' ' + checkedClass + '-' + cellIndex, isChecked );
|
||||
return $input.length ? status[ isChecked ? 0 : 1 ] : txt;
|
||||
},
|
||||
parsed : true, // filter widget flag
|
||||
|
Loading…
Reference in New Issue
Block a user