jquery-datatables-checkboxes
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -1,2 +0,2 @@ | ||
/*! Checkboxes 1.2.0-dev | ||
/*! Checkboxes 1.2.3 | ||
* Copyright (c) Gyrocode (www.gyrocode.com) | ||
@@ -9,3 +9,3 @@ * License: MIT License | ||
* @description Checkboxes extension for jQuery DataTables | ||
* @version 1.2.0-dev | ||
* @version 1.2.3 | ||
* @file dataTables.checkboxes.js | ||
@@ -77,3 +77,4 @@ * @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/) | ||
data: {}, | ||
ignoreSelect: false | ||
ignoreSelect: false, | ||
hasRender: false | ||
}; | ||
@@ -156,5 +157,9 @@ | ||
}; | ||
} else { | ||
// Indicate that this instance uses custom render function | ||
self.s.hasRender = true; | ||
} | ||
DataTable.ext.internal._fnColumnOptions( ctx, i, colOptions ); | ||
DataTable.ext.internal._fnColumnOptions(ctx, i, colOptions); | ||
@@ -242,4 +247,5 @@ | ||
if (ctx.aoColumns[colIdx].checkboxes){ | ||
var $input = $(dt.cell({ row: rowIdx, column: colIdx }).node()).find('.dt-checkboxes'); | ||
if($input.length == 0 || $input.prop('disabled')){ | ||
// If checkbox in the cell cannot be checked | ||
if(!self.isCellSelectable({ row: rowIdx, column: colIdx })){ | ||
// Prevent row selection | ||
e.preventDefault(); | ||
@@ -308,3 +314,3 @@ } | ||
$tableContainer.on('click.dtCheckboxes', 'thead th.dt-checkboxes-select-all', function(e) { | ||
$('input[type="checkbox"]', this).trigger('click'); | ||
$('input[type="checkbox"]', this).not(':disabled').trigger('click'); | ||
}); | ||
@@ -490,3 +496,3 @@ | ||
if(nodes.length){ | ||
$('input.dt-checkboxes', nodes).prop('checked', isSelected); | ||
$('input.dt-checkboxes', nodes).not(':disabled').prop('checked', isSelected); | ||
@@ -526,21 +532,24 @@ // NOTE: For performance reasons assume that cellSelector is always | ||
dt.cells('tr', self.s.columns, opts).every(function(cellRow, cellCol){ | ||
// Get cell data | ||
var cellData = this.data(); | ||
// If checkbox in the cell can be checked | ||
if(self.isCellSelectable({ row: cellRow, column: cellCol })){ | ||
// Get cell data | ||
var cellData = this.data(); | ||
// If data is in the list | ||
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; | ||
} | ||
// If data is in the list | ||
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; | ||
} | ||
// If cell needs to be selected | ||
if(dataSeen[cellData] <= ctx.checkboxes.s.data[cellCol][cellData]){ | ||
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); | ||
} | ||
} | ||
@@ -711,4 +720,4 @@ } | ||
var $tableContainer = dt.table().container(); | ||
var $checkboxes = $('.dt-checkboxes', cells.nodes()); | ||
var $checkboxesChecked = $checkboxes.filter(':checked'); | ||
var $checkboxes = $('.dt-checkboxes', cells.nodes()).not(':disabled'); | ||
var $checkboxesChecked = $checkboxes.filter(':checked').not(':disabled'); | ||
var $checkboxesSelectAll = $('.dt-checkboxes-select-all[data-col="' + colIdx + '"] input[type="checkbox"]', $tableContainer); | ||
@@ -806,2 +815,23 @@ | ||
// Determines whether checkbox in the cell can be checked | ||
isCellSelectable: function(selector){ | ||
var self = this; | ||
var dt = self.s.dt; | ||
var ctx = self.s.ctx; | ||
// If this instance uses custom render function | ||
if(self.s.hasRender){ | ||
// Determine whether checkbox can be checked | ||
// based on whether there is no `input` element | ||
// or it is disabled | ||
var $input = $(dt.cell(selector).node()).find('.dt-checkboxes'); | ||
return ($input.length === 0 || $input.is(':disabled')) ? false : true; | ||
// Otherwise, if this instance uses default render function | ||
} else { | ||
return true; | ||
} | ||
}, | ||
// Gets cell index | ||
@@ -925,6 +955,16 @@ getCellIndex: function(cell){ | ||
return this.iterator( 'column-rows', function ( ctx, colIdx, i, j, rowsIdx ) { | ||
var dt = this; | ||
if(ctx.checkboxes){ | ||
var selector = []; | ||
var rowsSelectableIdx = []; | ||
$.each(rowsIdx, function(index, rowIdx){ | ||
selector.push({ row: rowIdx, column: colIdx }); | ||
var cell = { row: rowIdx, column: colIdx }; | ||
// If checkbox in the cell can be checked | ||
if(ctx.checkboxes.isCellSelectable(cell)){ | ||
selector.push(cell); | ||
rowsSelectableIdx.push(rowIdx); | ||
} | ||
}); | ||
@@ -937,3 +977,3 @@ | ||
if(ctx.aoColumns[colIdx].checkboxes.selectRow){ | ||
ctx.checkboxes.updateSelect('row', rowsIdx, select); | ||
ctx.checkboxes.updateSelect('row', rowsSelectableIdx, select); | ||
} | ||
@@ -963,21 +1003,23 @@ | ||
ctx.checkboxes.updateData('cell', selector, (select) ? true : false, allowDups); | ||
ctx.checkboxes.updateCheckbox('cell', selector, (select) ? true : false); | ||
if(ctx.checkboxes.isCellSelectable(selector)){ | ||
ctx.checkboxes.updateData('cell', selector, (select) ? true : false, allowDups); | ||
ctx.checkboxes.updateCheckbox('cell', selector, (select) ? true : false); | ||
// If row selection is enabled | ||
if(ctx.aoColumns[colIdx].checkboxes.selectRow){ | ||
ctx.checkboxes.updateSelect('row', rowIdx, select); | ||
} | ||
// If row selection is enabled | ||
if(ctx.aoColumns[colIdx].checkboxes.selectRow){ | ||
ctx.checkboxes.updateSelect('row', rowIdx, select); | ||
} | ||
// If FixedColumns extension is enabled | ||
if(ctx._oFixedColumns){ | ||
// Use timeout to let FixedColumns construct the header | ||
// before we update the "Select all" checkbox | ||
setTimeout(function(){ ctx.checkboxes.updateSelectAll(colIdx); }, 0); | ||
// If FixedColumns extension is enabled | ||
if(ctx._oFixedColumns){ | ||
// Use timeout to let FixedColumns construct the header | ||
// before we update the "Select all" checkbox | ||
setTimeout(function(){ ctx.checkboxes.updateSelectAll(colIdx); }, 0); | ||
} else { | ||
ctx.checkboxes.updateSelectAll(colIdx); | ||
} else { | ||
ctx.checkboxes.updateSelectAll(colIdx); | ||
} | ||
ctx.checkboxes.updateFixedColumn(colIdx); | ||
} | ||
ctx.checkboxes.updateFixedColumn(colIdx); | ||
} | ||
@@ -1031,3 +1073,3 @@ }, 1 ); | ||
*/ | ||
Checkboxes.version = '1.2.0-dev'; | ||
Checkboxes.version = '1.2.3'; | ||
@@ -1034,0 +1076,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! Checkboxes 1.2.3 | ||
/*! Checkboxes 1.2.4 | ||
* Copyright (c) Gyrocode (www.gyrocode.com) | ||
@@ -9,3 +9,3 @@ * License: MIT License | ||
* @description Checkboxes extension for jQuery DataTables | ||
* @version 1.2.3 | ||
* @version 1.2.4 | ||
* @file dataTables.checkboxes.js | ||
@@ -166,3 +166,13 @@ * @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/) | ||
// If table has data source other than Ajax | ||
if(ctx.sAjaxSource === null){ | ||
// WORKAROUND: Invalidate column data | ||
var cells = dt.cells('tr', i); | ||
cells.invalidate('data'); | ||
// WORKAROUND: Add required class to existing cells | ||
$(cells.nodes()).addClass(colOptions['className']); | ||
} | ||
// | ||
@@ -169,0 +179,0 @@ // DATA |
@@ -1,5 +0,5 @@ | ||
/*! Checkboxes 1.2.3 | ||
/*! Checkboxes 1.2.4 | ||
* 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");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("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;})); |
{ | ||
"name": "jquery-datatables-checkboxes", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"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", |
@@ -7,3 +7,3 @@ jQuery DataTables Checkboxes | ||
More information and examples is available at | ||
More information and examples are available at | ||
[gyrocode.com/projects/jquery-datatables-checkboxes/](http://www.gyrocode.com/projects/jquery-datatables-checkboxes/). | ||
@@ -10,0 +10,0 @@ |
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
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
225276
12
4950
2
1