jquery-datatables-checkboxes
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -248,3 +248,3 @@ /*! Checkboxes 1.2.5-dev | ||
$table.on('user-select.dt.dtCheckboxes', function ( e, dt, type, cell, originalEvent ){ | ||
$table.on('user-select.dt.dtCheckboxes', function (e, dt, type, cell, originalEvent){ | ||
var cellIdx = cell.index(); | ||
@@ -254,3 +254,3 @@ var rowIdx = cellIdx.row; | ||
if (ctx.aoColumns[colIdx].checkboxes){ | ||
if(ctx.aoColumns[colIdx].checkboxes){ | ||
// If checkbox in the cell cannot be checked | ||
@@ -261,2 +261,8 @@ if(!self.isCellSelectable({ row: rowIdx, column: colIdx })){ | ||
} | ||
// WORKAROUND: Prevent duplicate checkbox select/deselect event | ||
// when "label" node is used in the column containing checkbox | ||
if(originalEvent.target.nodeName.toLowerCase() === 'label'){ | ||
e.preventDefault(); | ||
} | ||
} | ||
@@ -263,0 +269,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
/*! Checkboxes 1.2.4 | ||
/*! Checkboxes 1.2.5 | ||
* Copyright (c) Gyrocode (www.gyrocode.com) | ||
@@ -9,3 +9,3 @@ * License: MIT License | ||
* @description Checkboxes extension for jQuery DataTables | ||
* @version 1.2.4 | ||
* @version 1.2.5 | ||
* @file dataTables.checkboxes.js | ||
@@ -239,2 +239,15 @@ * @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/) | ||
// Handle event before row is selected/deselected | ||
$table.on('user-select.dt.dtCheckboxes', function ( e, dt, type, cell, originalEvent ){ | ||
var colIdx = self.getSelectRowColIndex(); | ||
// WORKAROUND: Prevent duplicate checkbox select/deselect event | ||
// when "label" node is used in the column containing checkbox | ||
if(ctx.aoColumns[colIdx].checkboxes){ | ||
if(originalEvent.target.nodeName.toLowerCase() === 'label'){ | ||
e.preventDefault(); | ||
} | ||
} | ||
}); | ||
// Handle row select/deselect event | ||
@@ -257,31 +270,2 @@ $table.on('select.dt.dtCheckboxes deselect.dt.dtCheckboxes', function(e, api, type, indexes){ | ||
// Handle Ajax request completion event | ||
$table.on('xhr.dt', function ( e, settings, json, xhr ) { | ||
// Retrieve stored state | ||
var state = dt.state.loaded(); | ||
$.each(self.s.columns, function(index, colIdx){ | ||
// Clear data | ||
self.s.data[colIdx] = {}; | ||
// If state is loaded and contains data for this column | ||
if(state && state.checkboxes && state.checkboxes.hasOwnProperty(colIdx)){ | ||
// Load previous state | ||
self.s.data[colIdx] = state.checkboxes[colIdx]; | ||
} | ||
}); | ||
// If state saving is enabled | ||
if(ctx.oFeatures.bStateSave){ | ||
// If server-side processing mode is not enabled | ||
// NOTE: Needed to avoid duplicate call to updateCheckboxes() in onDraw() | ||
if(!ctx.oFeatures.bServerSide){ | ||
// Update table state on next redraw | ||
$table.one('draw.dt.dtCheckboxes', function(e){ | ||
self.updateState(); | ||
}); | ||
} | ||
} | ||
}); | ||
// Handle table draw event | ||
@@ -338,3 +322,28 @@ $table.on('draw.dt.dtCheckboxes', function(e){ | ||
if(!ctx.oFeatures.bServerSide){ | ||
self.updateState(); | ||
// Handle Ajax request completion event | ||
// NOTE: Needed to update table state | ||
// if table is reloaded via ajax.reload() API method | ||
$table.on('xhr.dt', function ( e, settings, json, xhr ) { | ||
// Retrieve stored state | ||
var state = dt.state.loaded(); | ||
$.each(self.s.columns, function(index, colIdx){ | ||
// Clear data | ||
self.s.data[colIdx] = {}; | ||
// If state is loaded and contains data for this column | ||
if(state && state.checkboxes && state.checkboxes.hasOwnProperty(colIdx)){ | ||
// Load previous state | ||
self.s.data[colIdx] = state.checkboxes[colIdx]; | ||
} | ||
}); | ||
// Update table state on next redraw | ||
$table.one('draw.dt.dtCheckboxes', function(e){ | ||
self.updateState(); | ||
}); | ||
}); | ||
} | ||
@@ -375,3 +384,3 @@ | ||
// Updates array holding data for selected checkboxes | ||
updateData: function(type, selector, isSelected, allowDups){ | ||
updateData: function(type, selector, isSelected){ | ||
var self = this; | ||
@@ -381,5 +390,2 @@ var dt = self.s.dt; | ||
// By default, duplicate data is not allowed | ||
if(typeof allowDups === 'undefined'){ allowDups = false; } | ||
var cellSelector; | ||
@@ -408,26 +414,9 @@ | ||
// Determine whether data is in the list | ||
var hasData = ctx.checkboxes.s.data[cellCol].hasOwnProperty(cellData); | ||
// If checkbox is checked and data is not in the list | ||
// If checkbox is checked | ||
if(isSelected){ | ||
// If data is available and duplicates are allowed | ||
if(hasData && allowDups){ | ||
ctx.checkboxes.s.data[cellCol][cellData]++; | ||
ctx.checkboxes.s.data[cellCol][cellData] = 1; | ||
// Otherwise, if data is not available or duplicates are not allowed | ||
} else { | ||
ctx.checkboxes.s.data[cellCol][cellData] = 1; | ||
} | ||
// Otherwise, if checkbox is not checked and data is in the list | ||
} else if (!isSelected && hasData){ | ||
// If only data counter equals to 1 or duplicates are not allowed | ||
if(ctx.checkboxes.s.data[cellCol][cellData] === 1 || !allowDups){ | ||
delete ctx.checkboxes.s.data[cellCol][cellData]; | ||
// Otherwise, if data counter is greater than 1 and duplicates are allowed | ||
} else { | ||
ctx.checkboxes.s.data[cellCol][cellData]--; | ||
} | ||
// Otherwise, if checkbox is not checked | ||
} else { | ||
delete ctx.checkboxes.s.data[cellCol][cellData]; | ||
} | ||
@@ -522,3 +511,2 @@ } | ||
// Enumerate all cells | ||
var dataSeen = {}; | ||
dt.cells('tr', self.s.columns, opts).every(function(cellRow, cellCol){ | ||
@@ -530,17 +518,7 @@ // Get cell data | ||
if(ctx.checkboxes.s.data[cellCol].hasOwnProperty(cellData)){ | ||
// Determine how many times cell with given data was already selected | ||
if(dataSeen.hasOwnProperty(cellData)){ | ||
dataSeen[cellData]++; | ||
} else { | ||
dataSeen[cellData] = 1; | ||
} | ||
self.updateCheckbox('cell', [{ row: cellRow, column: cellCol }], true); | ||
// If cell needs to be selected | ||
if(dataSeen[cellData] <= ctx.checkboxes.s.data[cellCol][cellData]){ | ||
self.updateCheckbox('cell', [{ row: cellRow, column: cellCol }], true); | ||
// If row selection is enabled | ||
if(ctx.aoColumns[cellCol].checkboxes.selectRow){ | ||
self.updateSelect('row', cellRow, true); | ||
} | ||
// If row selection is enabled | ||
if(ctx.aoColumns[cellCol].checkboxes.selectRow){ | ||
self.updateSelect('row', cellRow, true); | ||
} | ||
@@ -619,17 +597,3 @@ } | ||
if(type === 'row'){ | ||
// By default, allow duplicate data | ||
var allowDup = true; | ||
// WORKAROUND: | ||
// Select extension may generate multiple select events for the same row | ||
// when selecting rows using SHIFT key and the following styles are used | ||
// 'os', 'multi+shift'. | ||
// | ||
// If user is selecting/deselecting multiple rows using SHIFT key | ||
if((ctx._select.style === 'os' || ctx._select.style === 'multi+shift') && indexes.length > 1){ | ||
// Disallow handling of rows with duplicate data | ||
allowDup = false; | ||
} | ||
self.updateData('row', indexes, (e.type === 'select') ? true : false, allowDup); | ||
self.updateData('row', indexes, (e.type === 'select') ? true : false); | ||
self.updateCheckbox('row', indexes, (e.type === 'select') ? true : false); | ||
@@ -783,3 +747,3 @@ | ||
if (ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){ | ||
countRows += ctx.checkboxes.s.data[colIdx][cellData]; | ||
countRows++; | ||
} | ||
@@ -920,3 +884,3 @@ } | ||
Api.registerPlural( 'columns().checkboxes.select()', 'column().checkboxes.select()', function ( select, allowDups ) { | ||
Api.registerPlural( 'columns().checkboxes.select()', 'column().checkboxes.select()', function ( select ) { | ||
if(typeof select === 'undefined'){ select = true; } | ||
@@ -931,3 +895,3 @@ | ||
ctx.checkboxes.updateData('cell', selector, (select) ? true : false, allowDups); | ||
ctx.checkboxes.updateData('cell', selector, (select) ? true : false); | ||
ctx.checkboxes.updateCheckbox('cell', selector, (select) ? true : false); | ||
@@ -955,3 +919,3 @@ | ||
Api.registerPlural( 'cells().checkboxes.select()', 'cell().checkboxes.select()', function ( select, allowDups ) { | ||
Api.registerPlural( 'cells().checkboxes.select()', 'cell().checkboxes.select()', function ( select ) { | ||
if(typeof select === 'undefined'){ select = true; } | ||
@@ -963,3 +927,3 @@ | ||
ctx.checkboxes.updateData('cell', selector, (select) ? true : false, allowDups); | ||
ctx.checkboxes.updateData('cell', selector, (select) ? true : false); | ||
ctx.checkboxes.updateCheckbox('cell', selector, (select) ? true : false); | ||
@@ -987,8 +951,8 @@ | ||
Api.registerPlural( 'columns().checkboxes.deselect()', 'column().checkboxes.deselect()', function ( allowDups ) { | ||
return this.checkboxes.select(false, allowDups); | ||
Api.registerPlural( 'columns().checkboxes.deselect()', 'column().checkboxes.deselect()', function () { | ||
return this.checkboxes.select(false); | ||
} ); | ||
Api.registerPlural( 'cells().checkboxes.deselect()', 'cell().checkboxes.deselect()', function ( allowDups ) { | ||
return this.checkboxes.select(false, allowDups); | ||
Api.registerPlural( 'cells().checkboxes.deselect()', 'cell().checkboxes.deselect()', function () { | ||
return this.checkboxes.select(false); | ||
} ); | ||
@@ -1002,3 +966,3 @@ | ||
this.column(colIdx).checkboxes.select(false, false); | ||
this.column(colIdx).checkboxes.select(false); | ||
} | ||
@@ -1014,5 +978,3 @@ }, 1 ); | ||
$.each(ctx.checkboxes.s.data[colIdx], function(cellData, countRows){ | ||
for(var i = 0; i < countRows; i++){ | ||
data.push(cellData); | ||
} | ||
data.push(cellData); | ||
}); | ||
@@ -1034,3 +996,3 @@ | ||
*/ | ||
Checkboxes.version = '1.2.3'; | ||
Checkboxes.version = '1.2.5'; | ||
@@ -1037,0 +999,0 @@ |
@@ -1,5 +0,5 @@ | ||
/*! Checkboxes 1.2.4 | ||
/*! Checkboxes 1.2.5 | ||
* Copyright (c) Gyrocode (www.gyrocode.com) | ||
* License: MIT License | ||
*/ | ||
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","datatables.net"],function($){return factory($,window,document);});}else{if(typeof exports==="object"){module.exports=function(root,$){if(!root){root=window;}if(!$||!$.fn.dataTable){$=require("datatables.net")(root,$).$;}return factory($,root,root.document);};}else{factory(jQuery,window,document);}}}(function($,window,document,undefined){var DataTable=$.fn.dataTable;var Checkboxes=function(settings){if(!DataTable.versionCheck||!DataTable.versionCheck("1.10.8")){throw"DataTables Checkboxes requires DataTables 1.10.8 or newer";}this.s={dt:new DataTable.Api(settings),columns:[],data:{},ignoreSelect:false};this.s.ctx=this.s.dt.settings()[0];if(this.s.ctx.checkboxes){return;}settings.checkboxes=this;this._constructor();};Checkboxes.prototype={_constructor:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var hasCheckboxes=false;var hasCheckboxesSelectRow=false;var state=dt.state.loaded();for(var i=0;i<ctx.aoColumns.length;i++){if(ctx.aoColumns[i].checkboxes){var $colHeader=$(dt.column(i).header());hasCheckboxes=true;if(!$.isPlainObject(ctx.aoColumns[i].checkboxes)){ctx.aoColumns[i].checkboxes={};}ctx.aoColumns[i].checkboxes=$.extend({},Checkboxes.defaults,ctx.aoColumns[i].checkboxes);var colOptions={"searchable":false,"orderable":false};if(ctx.aoColumns[i].sClass===""){colOptions["className"]="dt-body-center";}if(ctx.aoColumns[i].sWidthOrig===null){colOptions["width"]="1%";}if(ctx.aoColumns[i].mRender===null){colOptions["render"]=function(){return'<input type="checkbox" class="dt-checkboxes">';};}DataTable.ext.internal._fnColumnOptions(ctx,i,colOptions);$colHeader.removeClass("sorting");$colHeader.off(".dt");if(ctx.sAjaxSource===null){var cells=dt.cells("tr",i);cells.invalidate("data");$(cells.nodes()).addClass(colOptions["className"]);}self.s.data[i]={};if(state&&state.checkboxes&&state.checkboxes.hasOwnProperty(i)){self.s.data[i]=state.checkboxes[i];}self.s.columns.push(i);if(ctx.aoColumns[i].checkboxes.selectRow){if(ctx._select){hasCheckboxesSelectRow=true;}else{ctx.aoColumns[i].checkboxes.selectRow=false;}}if(ctx.aoColumns[i].checkboxes.selectAll){$colHeader.data("html",$colHeader.html());$colHeader.html('<input type="checkbox">').addClass("dt-checkboxes-select-all").attr("data-col",i);}}}if(hasCheckboxes){var $table=$(dt.table().node());var $tableBody=$(dt.table().body());var $tableContainer=$(dt.table().container());if(hasCheckboxesSelectRow){$table.addClass("dt-checkboxes-select");$table.on("select.dt.dtCheckboxes deselect.dt.dtCheckboxes",function(e,api,type,indexes){self.onSelect(e,type,indexes);});dt.select.info(false);$table.on("draw.dt.dtCheckboxes select.dt.dtCheckboxes deselect.dt.dtCheckboxes",function(){self.showInfoSelected();});}$table.on("xhr.dt",function(e,settings,json,xhr){var state=dt.state.loaded();$.each(self.s.columns,function(index,colIdx){self.s.data[colIdx]={};if(state&&state.checkboxes&&state.checkboxes.hasOwnProperty(colIdx)){self.s.data[colIdx]=state.checkboxes[colIdx];}});if(ctx.oFeatures.bStateSave){if(!ctx.oFeatures.bServerSide){$table.one("draw.dt.dtCheckboxes",function(e){self.updateState();});}}});$table.on("draw.dt.dtCheckboxes",function(e){self.onDraw(e);});$tableBody.on("click.dtCheckboxes","input.dt-checkboxes",function(e){self.onClick(e,this);});$tableContainer.on("click.dtCheckboxes",'thead th.dt-checkboxes-select-all input[type="checkbox"]',function(e){self.onClickSelectAll(e,this);});$tableContainer.on("click.dtCheckboxes","thead th.dt-checkboxes-select-all",function(e){$('input[type="checkbox"]',this).trigger("click");});$(document).on("click.dtCheckboxes",'.fixedHeader-floating thead th.dt-checkboxes-select-all input[type="checkbox"]',function(e){if(ctx._fixedHeader){if(ctx._fixedHeader.dom["header"].floating){self.onClickSelectAll(e,this);}}});$(document).on("click.dtCheckboxes",".fixedHeader-floating thead th.dt-checkboxes-select-all",function(e){if(ctx._fixedHeader){if(ctx._fixedHeader.dom["header"].floating){$('input[type="checkbox"]',this).trigger("click");}}});$table.on("init.dt.dtCheckboxes",function(){if(ctx.oFeatures.bStateSave){if(!ctx.oFeatures.bServerSide){self.updateState();}$table.on("stateSaveParams.dt.dtCheckboxes",function(e,settings,data){data.checkboxes=self.s.data;});}});$table.one("destroy.dt.dtCheckboxes",function(e,settings){$(document).off("click.dtCheckboxes");$tableContainer.on(".dtCheckboxes");$tableBody.off(".dtCheckboxes");$table.off(".dtCheckboxes");self.s.data={};$(".dt-checkboxes-select-all",$table).each(function(index,el){$(el).html($(el).data("html")).removeClass("dt-checkboxes-select-all");});});}},updateData:function(type,selector,isSelected,allowDups){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(typeof allowDups==="undefined"){allowDups=false;}var cellSelector;if(type==="cell"){cellSelector=selector;}else{if(type==="row"){cellSelector=[];dt.rows(selector).every(function(rowIdx){var colIdx=self.getSelectRowColIndex();if(colIdx!==null){cellSelector.push({row:rowIdx,column:colIdx});}});}}dt.cells(cellSelector).every(function(cellRow,cellCol){if(ctx.aoColumns[cellCol].checkboxes){var cellData=this.data();var hasData=ctx.checkboxes.s.data[cellCol].hasOwnProperty(cellData);if(isSelected){if(hasData&&allowDups){ctx.checkboxes.s.data[cellCol][cellData]++;}else{ctx.checkboxes.s.data[cellCol][cellData]=1;}}else{if(!isSelected&&hasData){if(ctx.checkboxes.s.data[cellCol][cellData]===1||!allowDups){delete ctx.checkboxes.s.data[cellCol][cellData];}else{ctx.checkboxes.s.data[cellCol][cellData]--;}}}}});if(ctx.oFeatures.bStateSave){dt.state.save();}},updateSelect:function(type,selector,isSelected){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx._select){self.s.ignoreSelect=true;if(isSelected){dt.rows(selector).select();}else{dt.rows(selector).deselect();}self.s.ignoreSelect=false;}},updateCheckbox:function(type,selector,isSelected){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var cellSelector=[];if(type==="row"){dt.rows(selector).every(function(rowIdx){var colIdx=self.getSelectRowColIndex();if(colIdx!==null){cellSelector.push({row:rowIdx,column:colIdx});}});}else{if(type==="cell"){cellSelector=selector;}}var nodes=dt.cells(cellSelector).nodes();if(nodes.length){$("input.dt-checkboxes",nodes).prop("checked",isSelected);var colIdx=cellSelector[0].column;if($.isFunction(ctx.aoColumns[colIdx].checkboxes.selectCallback)){ctx.aoColumns[colIdx].checkboxes.selectCallback(nodes,isSelected);}}},updateState:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;self.updateCheckboxes({page:"all",search:"none"});$.each(self.s.columns,function(index,colIdx){self.updateSelectAll(colIdx);});},updateCheckboxes:function(opts){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var dataSeen={};dt.cells("tr",self.s.columns,opts).every(function(cellRow,cellCol){var cellData=this.data();if(ctx.checkboxes.s.data[cellCol].hasOwnProperty(cellData)){if(dataSeen.hasOwnProperty(cellData)){dataSeen[cellData]++;}else{dataSeen[cellData]=1;}if(dataSeen[cellData]<=ctx.checkboxes.s.data[cellCol][cellData]){self.updateCheckbox("cell",[{row:cellRow,column:cellCol}],true);if(ctx.aoColumns[cellCol].checkboxes.selectRow){self.updateSelect("row",cellRow,true);}}}});},onClick:function(e,ctrl){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var cellSelector;var $cell=$(ctrl).closest("td");if($cell.parents(".DTFC_Cloned").length){cellSelector=dt.fixedColumns().cellIndex($cell);}else{cellSelector=$cell;}var cell=dt.cell(cellSelector);var cellIdx=cell.index();var colIdx=cellIdx.column;if(!ctx.aoColumns[colIdx].checkboxes.selectRow){cell.checkboxes.select(ctrl.checked,true);e.stopPropagation();}else{setTimeout(function(){var cellData=cell.data();var hasData=self.s.data[colIdx].hasOwnProperty(cellData);if(hasData!==ctrl.checked){self.updateCheckbox("cell",[cellIdx],hasData);self.updateSelectAll(colIdx);}},0);}},onSelect:function(e,type,indexes){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(self.s.ignoreSelect){return;}if(type==="row"){var allowDup=true;if((ctx._select.style==="os"||ctx._select.style==="multi+shift")&&indexes.length>1){allowDup=false;}self.updateData("row",indexes,(e.type==="select")?true:false,allowDup);self.updateCheckbox("row",indexes,(e.type==="select")?true:false);var colIdx=self.getSelectRowColIndex();if(colIdx!==null){self.updateSelectAll(colIdx);}}},onClickSelectAll:function(e,ctrl){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var colIdx=null;var $th=$(ctrl).closest("th");if($th.parents(".DTFC_Cloned").length){var cellIdx=dt.fixedColumns().cellIndex($th);colIdx=cellIdx.column;}else{colIdx=dt.column($th).index();}dt.column(colIdx,{page:((ctx.aoColumns[colIdx].checkboxes&&ctx.aoColumns[colIdx].checkboxes.selectAllPages)?"all":"current"),search:"applied"}).checkboxes.select(ctrl.checked,true);e.stopPropagation();},onDraw:function(e){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx.oFeatures.bServerSide){self.updateCheckboxes({page:"current",search:"none"});}$.each(self.s.columns,function(index,colIdx){self.updateSelectAll(colIdx);});},updateSelectAll:function(colIdx){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx.aoColumns[colIdx].checkboxes&&ctx.aoColumns[colIdx].checkboxes.selectAll){var cells=dt.cells("tr",colIdx,{page:((ctx.aoColumns[colIdx].checkboxes.selectAllPages)?"all":"current"),search:"applied"});var $tableContainer=dt.table().container();var $checkboxes=$(".dt-checkboxes",cells.nodes());var $checkboxesChecked=$checkboxes.filter(":checked");var $checkboxesSelectAll=$('.dt-checkboxes-select-all[data-col="'+colIdx+'"] input[type="checkbox"]',$tableContainer);if(ctx._fixedHeader){if(ctx._fixedHeader.dom["header"].floating){$checkboxesSelectAll=$('.fixedHeader-floating .dt-checkboxes-select-all[data-col="'+colIdx+'"] input[type="checkbox"]');}}var isSelected;var isIndeterminate;if($checkboxesChecked.length===0){isSelected=false;isIndeterminate=false;}else{if($checkboxesChecked.length===$checkboxes.length){isSelected=true;isIndeterminate=false;}else{isSelected=true;isIndeterminate=true;}}$checkboxesSelectAll.prop({"checked":isSelected,"indeterminate":isIndeterminate});if($.isFunction(ctx.aoColumns[colIdx].checkboxes.selectAllCallback)){ctx.aoColumns[colIdx].checkboxes.selectAllCallback($checkboxesSelectAll.closest("th").get(0),isSelected,isIndeterminate);}}},showInfoSelected:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(!ctx.aanFeatures.i){return;}var $output=$('<span class="select-info"/>');var add=function(name,num){$output.append($('<span class="select-item"/>').append(dt.i18n("select."+name+"s",{_:"%d "+name+"s selected",0:"",1:"1 "+name+" selected"},num)));};var colIdx=self.getSelectRowColIndex();if(colIdx!==null){var countRows=0;for(var cellData in ctx.checkboxes.s.data[colIdx]){if(ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){countRows+=ctx.checkboxes.s.data[colIdx][cellData];}}add("row",countRows);$.each(ctx.aanFeatures.i,function(i,el){var $el=$(el);var $existing=$el.children("span.select-info");if($existing.length){$existing.remove();}if($output.text()!==""){$el.append($output);}});}},getCellIndex:function(cell){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx._oFixedColumns){return dt.fixedColumns().cellIndex(cell);}else{return dt.cell(cell).index();}},getSelectRowColIndex:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var colIdx=null;for(var i=0;i<ctx.aoColumns.length;i++){if(ctx.aoColumns[i].checkboxes&&ctx.aoColumns[i].checkboxes.selectRow){colIdx=i;break;}}return colIdx;},updateFixedColumn:function(colIdx){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx._oFixedColumns){var leftCols=ctx._oFixedColumns.s.iLeftColumns;var rightCols=ctx.aoColumns.length-ctx._oFixedColumns.s.iRightColumns-1;if(colIdx<leftCols||colIdx>rightCols){dt.fixedColumns().update();}}}};Checkboxes.defaults={selectRow:false,selectAll:true,selectAllPages:true,selectCallback:null,selectAllCallback:null};var Api=$.fn.dataTable.Api;Api.register("checkboxes()",function(){return this;});Api.registerPlural("columns().checkboxes.select()","column().checkboxes.select()",function(select,allowDups){if(typeof select==="undefined"){select=true;}return this.iterator("column-rows",function(ctx,colIdx,i,j,rowsIdx){if(ctx.checkboxes){var selector=[];$.each(rowsIdx,function(index,rowIdx){selector.push({row:rowIdx,column:colIdx});});ctx.checkboxes.updateData("cell",selector,(select)?true:false,allowDups);ctx.checkboxes.updateCheckbox("cell",selector,(select)?true:false);if(ctx.aoColumns[colIdx].checkboxes.selectRow){ctx.checkboxes.updateSelect("row",rowsIdx,select);}if(ctx._oFixedColumns){setTimeout(function(){ctx.checkboxes.updateSelectAll(colIdx);},0);}else{ctx.checkboxes.updateSelectAll(colIdx);}ctx.checkboxes.updateFixedColumn(colIdx);}},1);});Api.registerPlural("cells().checkboxes.select()","cell().checkboxes.select()",function(select,allowDups){if(typeof select==="undefined"){select=true;}return this.iterator("cell",function(ctx,rowIdx,colIdx){if(ctx.checkboxes){var selector=[{row:rowIdx,column:colIdx}];ctx.checkboxes.updateData("cell",selector,(select)?true:false,allowDups);ctx.checkboxes.updateCheckbox("cell",selector,(select)?true:false);if(ctx.aoColumns[colIdx].checkboxes.selectRow){ctx.checkboxes.updateSelect("row",rowIdx,select);}if(ctx._oFixedColumns){setTimeout(function(){ctx.checkboxes.updateSelectAll(colIdx);},0);}else{ctx.checkboxes.updateSelectAll(colIdx);}ctx.checkboxes.updateFixedColumn(colIdx);}},1);});Api.registerPlural("columns().checkboxes.deselect()","column().checkboxes.deselect()",function(allowDups){return this.checkboxes.select(false,allowDups);});Api.registerPlural("cells().checkboxes.deselect()","cell().checkboxes.deselect()",function(allowDups){return this.checkboxes.select(false,allowDups);});Api.registerPlural("columns().checkboxes.deselectAll()","column().checkboxes.deselectAll()",function(){return this.iterator("column",function(ctx,colIdx){if(ctx.aoColumns[colIdx].checkboxes){ctx.checkboxes.s.data[colIdx]={};this.column(colIdx).checkboxes.select(false,false);}},1);});Api.registerPlural("columns().checkboxes.selected()","column().checkboxes.selected()",function(){return this.iterator("column",function(ctx,colIdx){if(ctx.aoColumns[colIdx].checkboxes){var data=[];$.each(ctx.checkboxes.s.data[colIdx],function(cellData,countRows){for(var i=0;i<countRows;i++){data.push(cellData);}});return data;}else{return[];}},1);});Checkboxes.version="1.2.3";$.fn.DataTable.Checkboxes=Checkboxes;$.fn.dataTable.Checkboxes=Checkboxes;$(document).on("preInit.dt.dtCheckboxes",function(e,settings,json){if(e.namespace!=="dt"){return;}new Checkboxes(settings);});return Checkboxes;})); | ||
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","datatables.net"],function($){return factory($,window,document);});}else{if(typeof exports==="object"){module.exports=function(root,$){if(!root){root=window;}if(!$||!$.fn.dataTable){$=require("datatables.net")(root,$).$;}return factory($,root,root.document);};}else{factory(jQuery,window,document);}}}(function($,window,document,undefined){var DataTable=$.fn.dataTable;var Checkboxes=function(settings){if(!DataTable.versionCheck||!DataTable.versionCheck("1.10.8")){throw"DataTables Checkboxes requires DataTables 1.10.8 or newer";}this.s={dt:new DataTable.Api(settings),columns:[],data:{},ignoreSelect:false};this.s.ctx=this.s.dt.settings()[0];if(this.s.ctx.checkboxes){return;}settings.checkboxes=this;this._constructor();};Checkboxes.prototype={_constructor:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var hasCheckboxes=false;var hasCheckboxesSelectRow=false;var state=dt.state.loaded();for(var i=0;i<ctx.aoColumns.length;i++){if(ctx.aoColumns[i].checkboxes){var $colHeader=$(dt.column(i).header());hasCheckboxes=true;if(!$.isPlainObject(ctx.aoColumns[i].checkboxes)){ctx.aoColumns[i].checkboxes={};}ctx.aoColumns[i].checkboxes=$.extend({},Checkboxes.defaults,ctx.aoColumns[i].checkboxes);var colOptions={"searchable":false,"orderable":false};if(ctx.aoColumns[i].sClass===""){colOptions["className"]="dt-body-center";}if(ctx.aoColumns[i].sWidthOrig===null){colOptions["width"]="1%";}if(ctx.aoColumns[i].mRender===null){colOptions["render"]=function(){return'<input type="checkbox" class="dt-checkboxes">';};}DataTable.ext.internal._fnColumnOptions(ctx,i,colOptions);$colHeader.removeClass("sorting");$colHeader.off(".dt");if(ctx.sAjaxSource===null){var cells=dt.cells("tr",i);cells.invalidate("data");$(cells.nodes()).addClass(colOptions["className"]);}self.s.data[i]={};if(state&&state.checkboxes&&state.checkboxes.hasOwnProperty(i)){self.s.data[i]=state.checkboxes[i];}self.s.columns.push(i);if(ctx.aoColumns[i].checkboxes.selectRow){if(ctx._select){hasCheckboxesSelectRow=true;}else{ctx.aoColumns[i].checkboxes.selectRow=false;}}if(ctx.aoColumns[i].checkboxes.selectAll){$colHeader.data("html",$colHeader.html());$colHeader.html('<input type="checkbox">').addClass("dt-checkboxes-select-all").attr("data-col",i);}}}if(hasCheckboxes){var $table=$(dt.table().node());var $tableBody=$(dt.table().body());var $tableContainer=$(dt.table().container());if(hasCheckboxesSelectRow){$table.addClass("dt-checkboxes-select");$table.on("user-select.dt.dtCheckboxes",function(e,dt,type,cell,originalEvent){var colIdx=self.getSelectRowColIndex();if(ctx.aoColumns[colIdx].checkboxes){if(originalEvent.target.nodeName.toLowerCase()==="label"){e.preventDefault();}}});$table.on("select.dt.dtCheckboxes deselect.dt.dtCheckboxes",function(e,api,type,indexes){self.onSelect(e,type,indexes);});dt.select.info(false);$table.on("draw.dt.dtCheckboxes select.dt.dtCheckboxes deselect.dt.dtCheckboxes",function(){self.showInfoSelected();});}$table.on("draw.dt.dtCheckboxes",function(e){self.onDraw(e);});$tableBody.on("click.dtCheckboxes","input.dt-checkboxes",function(e){self.onClick(e,this);});$tableContainer.on("click.dtCheckboxes",'thead th.dt-checkboxes-select-all input[type="checkbox"]',function(e){self.onClickSelectAll(e,this);});$tableContainer.on("click.dtCheckboxes","thead th.dt-checkboxes-select-all",function(e){$('input[type="checkbox"]',this).trigger("click");});$(document).on("click.dtCheckboxes",'.fixedHeader-floating thead th.dt-checkboxes-select-all input[type="checkbox"]',function(e){if(ctx._fixedHeader){if(ctx._fixedHeader.dom["header"].floating){self.onClickSelectAll(e,this);}}});$(document).on("click.dtCheckboxes",".fixedHeader-floating thead th.dt-checkboxes-select-all",function(e){if(ctx._fixedHeader){if(ctx._fixedHeader.dom["header"].floating){$('input[type="checkbox"]',this).trigger("click");}}});$table.on("init.dt.dtCheckboxes",function(){if(ctx.oFeatures.bStateSave){if(!ctx.oFeatures.bServerSide){self.updateState();$table.on("xhr.dt",function(e,settings,json,xhr){var state=dt.state.loaded();$.each(self.s.columns,function(index,colIdx){self.s.data[colIdx]={};if(state&&state.checkboxes&&state.checkboxes.hasOwnProperty(colIdx)){self.s.data[colIdx]=state.checkboxes[colIdx];}});$table.one("draw.dt.dtCheckboxes",function(e){self.updateState();});});}$table.on("stateSaveParams.dt.dtCheckboxes",function(e,settings,data){data.checkboxes=self.s.data;});}});$table.one("destroy.dt.dtCheckboxes",function(e,settings){$(document).off("click.dtCheckboxes");$tableContainer.on(".dtCheckboxes");$tableBody.off(".dtCheckboxes");$table.off(".dtCheckboxes");self.s.data={};$(".dt-checkboxes-select-all",$table).each(function(index,el){$(el).html($(el).data("html")).removeClass("dt-checkboxes-select-all");});});}},updateData:function(type,selector,isSelected){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var cellSelector;if(type==="cell"){cellSelector=selector;}else{if(type==="row"){cellSelector=[];dt.rows(selector).every(function(rowIdx){var colIdx=self.getSelectRowColIndex();if(colIdx!==null){cellSelector.push({row:rowIdx,column:colIdx});}});}}dt.cells(cellSelector).every(function(cellRow,cellCol){if(ctx.aoColumns[cellCol].checkboxes){var cellData=this.data();if(isSelected){ctx.checkboxes.s.data[cellCol][cellData]=1;}else{delete ctx.checkboxes.s.data[cellCol][cellData];}}});if(ctx.oFeatures.bStateSave){dt.state.save();}},updateSelect:function(type,selector,isSelected){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx._select){self.s.ignoreSelect=true;if(isSelected){dt.rows(selector).select();}else{dt.rows(selector).deselect();}self.s.ignoreSelect=false;}},updateCheckbox:function(type,selector,isSelected){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var cellSelector=[];if(type==="row"){dt.rows(selector).every(function(rowIdx){var colIdx=self.getSelectRowColIndex();if(colIdx!==null){cellSelector.push({row:rowIdx,column:colIdx});}});}else{if(type==="cell"){cellSelector=selector;}}var nodes=dt.cells(cellSelector).nodes();if(nodes.length){$("input.dt-checkboxes",nodes).prop("checked",isSelected);var colIdx=cellSelector[0].column;if($.isFunction(ctx.aoColumns[colIdx].checkboxes.selectCallback)){ctx.aoColumns[colIdx].checkboxes.selectCallback(nodes,isSelected);}}},updateState:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;self.updateCheckboxes({page:"all",search:"none"});$.each(self.s.columns,function(index,colIdx){self.updateSelectAll(colIdx);});},updateCheckboxes:function(opts){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;dt.cells("tr",self.s.columns,opts).every(function(cellRow,cellCol){var cellData=this.data();if(ctx.checkboxes.s.data[cellCol].hasOwnProperty(cellData)){self.updateCheckbox("cell",[{row:cellRow,column:cellCol}],true);if(ctx.aoColumns[cellCol].checkboxes.selectRow){self.updateSelect("row",cellRow,true);}}});},onClick:function(e,ctrl){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var cellSelector;var $cell=$(ctrl).closest("td");if($cell.parents(".DTFC_Cloned").length){cellSelector=dt.fixedColumns().cellIndex($cell);}else{cellSelector=$cell;}var cell=dt.cell(cellSelector);var cellIdx=cell.index();var colIdx=cellIdx.column;if(!ctx.aoColumns[colIdx].checkboxes.selectRow){cell.checkboxes.select(ctrl.checked,true);e.stopPropagation();}else{setTimeout(function(){var cellData=cell.data();var hasData=self.s.data[colIdx].hasOwnProperty(cellData);if(hasData!==ctrl.checked){self.updateCheckbox("cell",[cellIdx],hasData);self.updateSelectAll(colIdx);}},0);}},onSelect:function(e,type,indexes){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(self.s.ignoreSelect){return;}if(type==="row"){self.updateData("row",indexes,(e.type==="select")?true:false);self.updateCheckbox("row",indexes,(e.type==="select")?true:false);var colIdx=self.getSelectRowColIndex();if(colIdx!==null){self.updateSelectAll(colIdx);}}},onClickSelectAll:function(e,ctrl){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var colIdx=null;var $th=$(ctrl).closest("th");if($th.parents(".DTFC_Cloned").length){var cellIdx=dt.fixedColumns().cellIndex($th);colIdx=cellIdx.column;}else{colIdx=dt.column($th).index();}dt.column(colIdx,{page:((ctx.aoColumns[colIdx].checkboxes&&ctx.aoColumns[colIdx].checkboxes.selectAllPages)?"all":"current"),search:"applied"}).checkboxes.select(ctrl.checked,true);e.stopPropagation();},onDraw:function(e){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx.oFeatures.bServerSide){self.updateCheckboxes({page:"current",search:"none"});}$.each(self.s.columns,function(index,colIdx){self.updateSelectAll(colIdx);});},updateSelectAll:function(colIdx){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx.aoColumns[colIdx].checkboxes&&ctx.aoColumns[colIdx].checkboxes.selectAll){var cells=dt.cells("tr",colIdx,{page:((ctx.aoColumns[colIdx].checkboxes.selectAllPages)?"all":"current"),search:"applied"});var $tableContainer=dt.table().container();var $checkboxes=$(".dt-checkboxes",cells.nodes());var $checkboxesChecked=$checkboxes.filter(":checked");var $checkboxesSelectAll=$('.dt-checkboxes-select-all[data-col="'+colIdx+'"] input[type="checkbox"]',$tableContainer);if(ctx._fixedHeader){if(ctx._fixedHeader.dom["header"].floating){$checkboxesSelectAll=$('.fixedHeader-floating .dt-checkboxes-select-all[data-col="'+colIdx+'"] input[type="checkbox"]');}}var isSelected;var isIndeterminate;if($checkboxesChecked.length===0){isSelected=false;isIndeterminate=false;}else{if($checkboxesChecked.length===$checkboxes.length){isSelected=true;isIndeterminate=false;}else{isSelected=true;isIndeterminate=true;}}$checkboxesSelectAll.prop({"checked":isSelected,"indeterminate":isIndeterminate});if($.isFunction(ctx.aoColumns[colIdx].checkboxes.selectAllCallback)){ctx.aoColumns[colIdx].checkboxes.selectAllCallback($checkboxesSelectAll.closest("th").get(0),isSelected,isIndeterminate);}}},showInfoSelected:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(!ctx.aanFeatures.i){return;}var $output=$('<span class="select-info"/>');var add=function(name,num){$output.append($('<span class="select-item"/>').append(dt.i18n("select."+name+"s",{_:"%d "+name+"s selected",0:"",1:"1 "+name+" selected"},num)));};var colIdx=self.getSelectRowColIndex();if(colIdx!==null){var countRows=0;for(var cellData in ctx.checkboxes.s.data[colIdx]){if(ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){countRows++;}}add("row",countRows);$.each(ctx.aanFeatures.i,function(i,el){var $el=$(el);var $existing=$el.children("span.select-info");if($existing.length){$existing.remove();}if($output.text()!==""){$el.append($output);}});}},getCellIndex:function(cell){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx._oFixedColumns){return dt.fixedColumns().cellIndex(cell);}else{return dt.cell(cell).index();}},getSelectRowColIndex:function(){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;var colIdx=null;for(var i=0;i<ctx.aoColumns.length;i++){if(ctx.aoColumns[i].checkboxes&&ctx.aoColumns[i].checkboxes.selectRow){colIdx=i;break;}}return colIdx;},updateFixedColumn:function(colIdx){var self=this;var dt=self.s.dt;var ctx=self.s.ctx;if(ctx._oFixedColumns){var leftCols=ctx._oFixedColumns.s.iLeftColumns;var rightCols=ctx.aoColumns.length-ctx._oFixedColumns.s.iRightColumns-1;if(colIdx<leftCols||colIdx>rightCols){dt.fixedColumns().update();}}}};Checkboxes.defaults={selectRow:false,selectAll:true,selectAllPages:true,selectCallback:null,selectAllCallback:null};var Api=$.fn.dataTable.Api;Api.register("checkboxes()",function(){return this;});Api.registerPlural("columns().checkboxes.select()","column().checkboxes.select()",function(select){if(typeof select==="undefined"){select=true;}return this.iterator("column-rows",function(ctx,colIdx,i,j,rowsIdx){if(ctx.checkboxes){var selector=[];$.each(rowsIdx,function(index,rowIdx){selector.push({row:rowIdx,column:colIdx});});ctx.checkboxes.updateData("cell",selector,(select)?true:false);ctx.checkboxes.updateCheckbox("cell",selector,(select)?true:false);if(ctx.aoColumns[colIdx].checkboxes.selectRow){ctx.checkboxes.updateSelect("row",rowsIdx,select);}if(ctx._oFixedColumns){setTimeout(function(){ctx.checkboxes.updateSelectAll(colIdx);},0);}else{ctx.checkboxes.updateSelectAll(colIdx);}ctx.checkboxes.updateFixedColumn(colIdx);}},1);});Api.registerPlural("cells().checkboxes.select()","cell().checkboxes.select()",function(select){if(typeof select==="undefined"){select=true;}return this.iterator("cell",function(ctx,rowIdx,colIdx){if(ctx.checkboxes){var selector=[{row:rowIdx,column:colIdx}];ctx.checkboxes.updateData("cell",selector,(select)?true:false);ctx.checkboxes.updateCheckbox("cell",selector,(select)?true:false);if(ctx.aoColumns[colIdx].checkboxes.selectRow){ctx.checkboxes.updateSelect("row",rowIdx,select);}if(ctx._oFixedColumns){setTimeout(function(){ctx.checkboxes.updateSelectAll(colIdx);},0);}else{ctx.checkboxes.updateSelectAll(colIdx);}ctx.checkboxes.updateFixedColumn(colIdx);}},1);});Api.registerPlural("columns().checkboxes.deselect()","column().checkboxes.deselect()",function(){return this.checkboxes.select(false);});Api.registerPlural("cells().checkboxes.deselect()","cell().checkboxes.deselect()",function(){return this.checkboxes.select(false);});Api.registerPlural("columns().checkboxes.deselectAll()","column().checkboxes.deselectAll()",function(){return this.iterator("column",function(ctx,colIdx){if(ctx.aoColumns[colIdx].checkboxes){ctx.checkboxes.s.data[colIdx]={};this.column(colIdx).checkboxes.select(false);}},1);});Api.registerPlural("columns().checkboxes.selected()","column().checkboxes.selected()",function(){return this.iterator("column",function(ctx,colIdx){if(ctx.aoColumns[colIdx].checkboxes){var data=[];$.each(ctx.checkboxes.s.data[colIdx],function(cellData,countRows){data.push(cellData);});return data;}else{return[];}},1);});Checkboxes.version="1.2.5";$.fn.DataTable.Checkboxes=Checkboxes;$.fn.dataTable.Checkboxes=Checkboxes;$(document).on("preInit.dt.dtCheckboxes",function(e,settings,json){if(e.namespace!=="dt"){return;}new Checkboxes(settings);});return Checkboxes;})); |
{ | ||
"name": "jquery-datatables-checkboxes", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "Checkboxes is an extension for the jQuery DataTables library that provides universal solution for working with checkboxes in a table.", | ||
@@ -5,0 +5,0 @@ "main": "./js/dataTables.checkboxes.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
117070
8
2573