forked from gyrocode/jquery-datatables-checkboxes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataTables.checkboxes.min.js
3 lines (3 loc) · 15.4 KB
/
dataTables.checkboxes.min.js
1
2
3
/*! jQuery DataTables Checkboxes v1.3.0 - www.gyrocode.com/projects/jquery-datatables-checkboxes/ - License: MIT - Author: Gyrocode LLC / www.gyrocode.com */
!function(c){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return c(e,window,document)}):"object"==typeof exports?module.exports=function(e,t){return e=e||window,t&&t.fn.dataTable||(t=require("datatables.net")(e,t).$),c(t,e,e.document)}:c(jQuery,window,document)}(function(u,n,b){"use strict";function x(e){if(!k.versionCheck||!k.versionCheck("1.10.8"))throw"DataTables Checkboxes requires DataTables 1.10.8 or newer";this.s={dt:new k.Api(e),columns:[],data:{},dataDisabled:{},ignoreSelect:!1},this.s.ctx=this.s.dt.settings()[0],this.s.ctx.checkboxes||(e.checkboxes=this)._constructor()}var k=u.fn.dataTable,e=(x.prototype={_constructor:function(){for(var e,t,c,s,o,a,l=this,n=l.s.dt,r=l.s.ctx,i=!1,d=!1,h=0;h<r.aoColumns.length;h++)r.aoColumns[h].checkboxes&&(e=u(n.column(h).header()),i=!0,u.isPlainObject(r.aoColumns[h].checkboxes)||(r.aoColumns[h].checkboxes={}),r.aoColumns[h].checkboxes=u.extend({},x.defaults,r.aoColumns[h].checkboxes),t={searchable:!1,orderable:!1},""===r.aoColumns[h].sClass?t.className="dt-checkboxes-cell":t.className=r.aoColumns[h].sClass+" dt-checkboxes-cell",null===r.aoColumns[h].sWidthOrig&&(t.width="1%"),null===r.aoColumns[h].mRender&&(t.render=function(){return'<input type="checkbox" class="dt-checkboxes" autocomplete="off">'}),(k.versionCheck("2")?l:k.ext.internal)._fnColumnOptions(r,h,t),e.removeClass("sorting"),e.off(".dt"),null!==r.sAjaxSource&&null!=r.ajax||((c=n.cells("tr",h)).invalidate("data"),u(c.nodes()).addClass(t.className)),l.s.data[h]={},l.s.dataDisabled[h]={},l.s.columns.push(h),r.aoColumns[h].checkboxes.selectRow&&(r._select?d=!0:r.aoColumns[h].checkboxes.selectRow=!1),r.aoColumns[h].checkboxes.selectAll)&&(e.data("html",e.html()),null!==r.aoColumns[h].checkboxes.selectAllRender)&&(c="",u.isFunction(r.aoColumns[h].checkboxes.selectAllRender)?c=r.aoColumns[h].checkboxes.selectAllRender():"string"==typeof r.aoColumns[h].checkboxes.selectAllRender&&(c=r.aoColumns[h].checkboxes.selectAllRender),e.html(c).addClass("dt-checkboxes-select-all").attr("data-col",h));i&&(l.loadState(),s=u(n.table().node()),o=u(n.table().body()),a=u(n.table().container()),d&&(s.addClass("dt-checkboxes-select"),s.on("user-select.dt.dtCheckboxes",function(e,t,c,s,o){l.onDataTablesUserSelect(e,t,c,s,o)}),s.on("select.dt.dtCheckboxes deselect.dt.dtCheckboxes",function(e,t,c,s){l.onDataTablesSelectDeselect(e,c,s)}),r._select.info)&&(n.select.info(!1),s.on("draw.dt.dtCheckboxes select.dt.dtCheckboxes deselect.dt.dtCheckboxes",function(){l.showInfoSelected()})),s.on("draw.dt.dtCheckboxes",function(e){l.onDataTablesDraw(e)}),o.on("click.dtCheckboxes","input.dt-checkboxes",function(e){l.onClick(e,this)}),a.on("click.dtCheckboxes",'thead th.dt-checkboxes-select-all input[type="checkbox"]',function(e){l.onClickSelectAll(e,this)}),a.on("click.dtCheckboxes","thead th.dt-checkboxes-select-all",function(){u('input[type="checkbox"]',this).not(":disabled").trigger("click")}),d||a.on("click.dtCheckboxes","tbody td.dt-checkboxes-cell",function(){u('input[type="checkbox"]',this).not(":disabled").trigger("click")}),a.on("click.dtCheckboxes","thead th.dt-checkboxes-select-all label, tbody td.dt-checkboxes-cell label",function(e){e.preventDefault()}),u(b).on("click.dtCheckboxes",'.fixedHeader-floating thead th.dt-checkboxes-select-all input[type="checkbox"]',function(e){r._fixedHeader&&r._fixedHeader.dom.header.floating&&l.onClickSelectAll(e,this)}),u(b).on("click.dtCheckboxes",".fixedHeader-floating thead th.dt-checkboxes-select-all",function(){r._fixedHeader&&r._fixedHeader.dom.header.floating&&u('input[type="checkbox"]',this).trigger("click")}),s.on("init.dt.dtCheckboxes",function(){setTimeout(function(){l.onDataTablesInit()},0)}),s.on("stateSaveParams.dt.dtCheckboxes",function(e,t,c){l.onDataTablesStateSave(e,t,c)}),s.one("destroy.dt.dtCheckboxes",function(e,t){l.onDataTablesDestroy(e,t)}))},_fnCompatCols:function(e){this._fnCompatMap(e,"orderable","bSortable"),this._fnCompatMap(e,"render","mRender"),this._fnCompatMap(e,"orderData","aDataSort"),this._fnCompatMap(e,"orderSequence","asSorting"),this._fnCompatMap(e,"orderDataType","sortDataType");var t=e.aDataSort;"number"!=typeof t||Array.isArray(t)||(e.aDataSort=[t])},_fnCompatMap:function(e,t,c){void 0!==e[t]&&(e[c]=e[t])},_fnMap:function(c,s,e,t){Array.isArray(e)?u.each(e,function(e,t){Array.isArray(t)?_fnMap(c,s,t[0],t[1]):_fnMap(c,s,t)}):(void 0===t&&(t=e),void 0!==s[e]&&(c[t]=s[e]))},_fnColumnOptions:function(e,t,c){function s(e){return"string"==typeof e&&-1!==e.indexOf("@")}var o=e.aoColumns[t],a=(null!=c&&(this._fnCompatCols(c),void 0===c.mDataProp||c.mData||(c.mData=c.mDataProp),c.sType&&(o._sManualType=c.sType),c.className&&!c.sClass&&(c.sClass=c.className),t=o.sClass,u.extend(o,c),this._fnMap(o,c,"sWidth","sWidthOrig"),t!==o.sClass&&(o.sClass=t+" "+o.sClass),void 0!==c.iDataSort&&(o.aDataSort=[c.iDataSort]),this._fnMap(o,c,"aDataSort")),o.mData),l=k.util.get(a);o.mRender&&Array.isArray(o.mRender)&&(c=(t=o.mRender.slice()).shift(),o.mRender=k.render[c].apply(n,t)),o._render=o.mRender?k.util.get(o.mRender):null;o._bAttrSrc=u.isPlainObject(a)&&(s(a.sort)||s(a.type)||s(a.filter)),o._setter=null,o.fnGetData=function(e,t,c){var s=l(e,t,void 0,c);return o._render&&t?o._render(s,t,e,c):s},o.fnSetData=function(e,t,c){return k.util.set(a)(e,t,c)},"number"==typeof a||o._isArrayHost||(e._rowReadObject=!0),e.oFeatures.bSort||(o.bSortable=!1)},onDataTablesInit:function(){var o=this,e=o.s.dt,t=o.s.ctx;t.oFeatures.bServerSide||(t.oFeatures.bStateSave&&o.updateState(),u(e.table().node()).on("xhr.dt.dtCheckboxes",function(e,t,c,s){o.onDataTablesXhr(e.settings,c,s)}))},onDataTablesUserSelect:function(e,t,c,s){var s=s.index().row,o=this.getSelectRowColIndex(),t=t.cell({row:s,column:o}).data();this.isCellSelectable(o,t)||e.preventDefault()},onDataTablesSelectDeselect:function(e,t,c){var s=this,o=s.s.dt;s.s.ignoreSelect||"row"===t&&null!==(t=s.getSelectRowColIndex())&&(c=o.cells(c,t),s.updateData(c,t,"select"===e.type),s.updateCheckbox(c,t,"select"===e.type),s.updateSelectAll(t),-1!=u.inArray(e.type,["select","deselect"]))&&o.trigger(e.type+".dtcheckboxes",[s,c])},onDataTablesStateSave:function(e,t,c){var s=this,o=s.s.ctx;u.each(s.s.columns,function(e,t){o.aoColumns[t].checkboxes.stateSave&&(Object.prototype.hasOwnProperty.call(c,"checkboxes")||(c.checkboxes=[]),c.checkboxes[t]=s.s.data[t])})},onDataTablesDestroy:function(){var e=this.s.dt,t=u(e.table().node()),c=u(e.table().body()),e=u(e.table().container());u(b).off("click.dtCheckboxes"),e.off(".dtCheckboxes"),c.off(".dtCheckboxes"),t.off(".dtCheckboxes"),this.s.data={},this.s.dataDisabled={},u(".dt-checkboxes-select-all",t).each(function(e,t){u(t).html(u(t).data("html")).removeClass("dt-checkboxes-select-all")})},onDataTablesDraw:function(){var c=this,e=c.s.ctx;(e.oFeatures.bServerSide||e.oFeatures.bDeferRender)&&c.updateStateCheckboxes({page:"current",search:"none"}),u.each(c.s.columns,function(e,t){c.updateSelectAll(t)})},onDataTablesXhr:function(){var c=this,e=c.s.dt,t=c.s.ctx,e=u(e.table().node());u.each(c.s.columns,function(e,t){c.s.data[t]={},c.s.dataDisabled[t]={}}),t.oFeatures.bStateSave&&(c.loadState(),e.one("draw.dt.dtCheckboxes",function(){c.updateState()}))},updateData:function(e,t,c){var s=this.s.dt,o=this.s.ctx;o.aoColumns[t].checkboxes&&(e.data().each(function(e){c?o.checkboxes.s.data[t][e]=1:delete o.checkboxes.s.data[t][e]}),o.oFeatures.bStateSave)&&o.aoColumns[t].checkboxes.stateSave&&s.state.save()},updateSelect:function(e,t){var c=this.s.dt;this.s.ctx._select&&(this.s.ignoreSelect=!0,t?c.rows(e).select():c.rows(e).deselect(),this.s.ignoreSelect=!1)},updateCheckbox:function(e,t,c){var s=this.s.ctx,e=e.nodes?e.nodes():[e.node()];e.length&&(u("input.dt-checkboxes",e).not(":disabled").prop("checked",c),u.isFunction(s.aoColumns[t].checkboxes.selectCallback))&&s.aoColumns[t].checkboxes.selectCallback(e,c)},updateState:function(){var c=this,e=(c.s.dt,c.s.ctx);c.updateStateCheckboxes({page:"all",search:"none"}),e._oFixedColumns&&setTimeout(function(){u.each(c.s.columns,function(e,t){c.updateSelectAll(t)})},0)},updateStateCheckboxes:function(e){var o=this,t=o.s.dt,a=o.s.ctx;t.cells("tr",o.s.columns,e).every(function(e,t){var c=this.data(),s=o.isCellSelectable(t,c);Object.prototype.hasOwnProperty.call(a.checkboxes.s.data,t)&&Object.prototype.hasOwnProperty.call(a.checkboxes.s.data[t],c)&&(a.aoColumns[t].checkboxes.selectRow&&s&&o.updateSelect(e,!0),o.updateCheckbox(this,t,!0)),s||u("input.dt-checkboxes",this.node()).prop("disabled",!0)})},onClick:function(e,t){var c=this,s=c.s.dt,o=c.s.ctx,a=u(t).closest("td"),a=a.parents(".DTFC_Cloned").length?s.fixedColumns().cellIndex(a):a,l=s.cell(a),s=l.index(),n=s.column;s.row;o.aoColumns[n].checkboxes.selectRow?o._select&&("os"===o._select.style?(e.stopPropagation(),l.checkboxes.select(t.checked)):setTimeout(function(){var e=l.data(),e=Object.prototype.hasOwnProperty.call(c.s.data,n)&&Object.prototype.hasOwnProperty.call(c.s.data[n],e);e!==t.checked&&(c.updateCheckbox(l,n,e),c.updateSelectAll(n))},0)):(l.checkboxes.select(t.checked),e.stopPropagation())},onClickSelectAll:function(e,t){var c=this.s.dt,s=this.s.ctx,o=null,a=u(t).closest("th");o=a.parents(".DTFC_Cloned").length?c.fixedColumns().cellIndex(a).column:c.column(a).index(),u(t).data("is-changed",!0),c.column(o,{page:s.aoColumns[o].checkboxes&&s.aoColumns[o].checkboxes.selectAllPages?"all":"current",search:"applied"}).checkboxes.select(t.checked),e.stopPropagation()},loadState:function(){var c,s=this,e=s.s.dt,o=s.s.ctx;o.oFeatures.bStateSave&&(c=e.state.loaded(),u.each(s.s.columns,function(e,t){c&&c.checkboxes&&c.checkboxes.hasOwnProperty(t)&&o.aoColumns[t].checkboxes.stateSave&&(s.s.data[t]=c.checkboxes[t])}))},updateSelectAll:function(c){var s,o,e,t,a,l,n,r=this,i=r.s.dt,d=r.s.ctx;d.aoColumns[c].checkboxes&&d.aoColumns[c].checkboxes.selectAll&&(t=i.cells("tr",c,{page:d.aoColumns[c].checkboxes.selectAllPages?"all":"current",search:"applied"}),i=i.table().container(),i=u('.dt-checkboxes-select-all[data-col="'+c+'"] input[type="checkbox"]',i),o=s=0,t=t.data(),u.each(t,function(e,t){r.isCellSelectable(c,t)?Object.prototype.hasOwnProperty.call(r.s.data,c)&&Object.prototype.hasOwnProperty.call(r.s.data[c],t)&&s++:o++}),d._fixedHeader&&d._fixedHeader.dom.header.floating&&(i=u('.fixedHeader-floating .dt-checkboxes-select-all[data-col="'+c+'"] input[type="checkbox"]')),t=0===s?e=!1:s+o===t.length?!(e=!0):e=!0,a=i.data("is-changed"),l=i.prop("checked"),n=i.prop("indeterminate"),a||l!==e||n!==t)&&(i.data("is-changed",!1),i.prop({checked:!t&&e,indeterminate:t}),u.isFunction(d.aoColumns[c].checkboxes.selectAllCallback))&&d.aoColumns[c].checkboxes.selectAllCallback(i.closest("th").get(0),e,t)},showInfoSelected:function(){var a=this.s.dt,e=this.s.ctx;if(e.oFeatures.bInfo||e.aanFeatures.i){var t=this.getSelectRowColIndex();if(null!==t){var c,l=0;for(c in e.checkboxes.s.data[t])Object.prototype.hasOwnProperty.call(e.checkboxes.s.data,t)&&Object.prototype.hasOwnProperty.call(e.checkboxes.s.data[t],c)&&l++;var s;e.aanFeatures.i?s=e.aanFeatures.i:e.oClasses&&(s=["."+e.oClasses.info.container]),u.each(s,function(e,t){var c,t=u(t),s=u('<span class="select-info"/>'),o=(o="row",c=l,s.append(u('<span class="select-item"/>').append(a.i18n("select."+o+"s",{_:"%d "+o+"s selected",0:"",1:"1 "+o+" selected"},c))),t.children("span.select-info"));o.length&&o.remove(),""!==s.text()&&t.append(s)})}}},isCellSelectable:function(e,t){var c=this.s.ctx;return!Object.prototype.hasOwnProperty.call(c.checkboxes.s.dataDisabled,e)||!Object.prototype.hasOwnProperty.call(c.checkboxes.s.dataDisabled[e],t)},getCellIndex:function(e){var t=this.s.dt;return this.s.ctx._oFixedColumns?t.fixedColumns().cellIndex(e):t.cell(e).index()},getSelectRowColIndex:function(){for(var e=this.s.ctx,t=null,c=0;c<e.aoColumns.length;c++)if(e.aoColumns[c].checkboxes&&e.aoColumns[c].checkboxes.selectRow){t=c;break}return t},updateFixedColumn:function(e){var t,c=this,s=c.s.dt,o=c.s.ctx;o._oFixedColumns&&(t=o._oFixedColumns.s.iLeftColumns,o=o.aoColumns.length-o._oFixedColumns.s.iRightColumns-1,e<t||o<e)&&(s.fixedColumns().update(),setTimeout(function(){u.each(c.s.columns,function(e,t){c.updateSelectAll(t)})},0))}},x.defaults={stateSave:!0,selectRow:!1,selectAll:!0,selectAllPages:!0,selectCallback:null,selectAllCallback:null,selectAllRender:'<input type="checkbox" autocomplete="off">'},u.fn.dataTable.Api);return e.register("checkboxes()",function(){return this}),e.registerPlural("columns().checkboxes.select()","column().checkboxes.select()",function(i){return void 0===i&&(i=!0),this.iterator("column-rows",function(c,s,e,t,o){var a,l,n,r;c.aoColumns[s].checkboxes&&(r=[],u.each(o,function(e,t){r.push({row:t,column:s})}),l=(a=this.cells(r)).data(),n=[],r=[],u.each(l,function(e,t){c.checkboxes.isCellSelectable(s,t)&&(r.push({row:o[e],column:s}),n.push(o[e]))}),a=this.cells(r),c.checkboxes.updateData(a,s,i),c.aoColumns[s].checkboxes.selectRow&&c.checkboxes.updateSelect(n,i),c.checkboxes.updateCheckbox(a,s,i),c.checkboxes.updateSelectAll(s),c.checkboxes.updateFixedColumn(s))},1)}),e.registerPlural("cells().checkboxes.select()","cell().checkboxes.select()",function(a){return void 0===a&&(a=!0),this.iterator("cell",function(e,t,c){var s,o;e.aoColumns[c].checkboxes&&(s=this.cells([{row:t,column:c}]),o=this.cell({row:t,column:c}).data(),e.checkboxes.isCellSelectable(c,o))&&(e.checkboxes.updateData(s,c,a),e.aoColumns[c].checkboxes.selectRow&&e.checkboxes.updateSelect(t,a),e.checkboxes.updateCheckbox(s,c,a),e.checkboxes.updateSelectAll(c),e.checkboxes.updateFixedColumn(c))},1)}),e.registerPlural("cells().checkboxes.enable()","cell().checkboxes.enable()",function(a){return void 0===a&&(a=!0),this.iterator("cell",function(e,t,c){var s,o;e.aoColumns[c].checkboxes&&(s=(o=this.cell({row:t,column:c})).data(),a?delete e.checkboxes.s.dataDisabled[c][s]:e.checkboxes.s.dataDisabled[c][s]=1,(o=o.node())&&u("input.dt-checkboxes",o).prop("disabled",!a),e.aoColumns[c].checkboxes.selectRow)&&Object.prototype.hasOwnProperty.call(e.checkboxes.s.data,c)&&Object.prototype.hasOwnProperty.call(e.checkboxes.s.data[c],s)&&e.checkboxes.updateSelect(t,a)},1)}),e.registerPlural("cells().checkboxes.disable()","cell().checkboxes.disable()",function(e){return this.checkboxes.enable(!(e=void 0===e?!0:e))}),e.registerPlural("columns().checkboxes.deselect()","column().checkboxes.deselect()",function(e){return this.checkboxes.select(!(e=void 0===e?!0:e))}),e.registerPlural("cells().checkboxes.deselect()","cell().checkboxes.deselect()",function(e){return this.checkboxes.select(!(e=void 0===e?!0:e))}),e.registerPlural("columns().checkboxes.deselectAll()","column().checkboxes.deselectAll()",function(){return this.iterator("column",function(e,t){e.aoColumns[t].checkboxes&&(e.checkboxes.s.data[t]={},this.column(t).checkboxes.select(!1))},1)}),e.registerPlural("columns().checkboxes.selected()","column().checkboxes.selected()",function(){return this.iterator("column-rows",function(c,s,e,t,o){var a,l;return c.aoColumns[s].checkboxes?(a=[],c.oFeatures.bServerSide?u.each(c.checkboxes.s.data[s],function(e){c.checkboxes.isCellSelectable(s,e)&&a.push(e)}):(l=[],u.each(o,function(e,t){l.push({row:t,column:s})}),o=this.cells(l).data(),u.each(o,function(e,t){Object.prototype.hasOwnProperty.call(c.checkboxes.s.data,s)&&Object.prototype.hasOwnProperty.call(c.checkboxes.s.data[s],t)&&c.checkboxes.isCellSelectable(s,t)&&a.push(t)})),a):[]},1)}),x.version="1.2.14",u.fn.DataTable.Checkboxes=x,u.fn.dataTable.Checkboxes=x,u(b).on("preInit.dt.dtCheckboxes",function(e,t){"dt"===e.namespace&&new x(t)}),x});
//# sourceMappingURL=dataTables.checkboxes.min.js.map