Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for selectableCount to limit count when using selectable: "highlight" #3590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/js/modules/SelectRow/SelectRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SelectRow extends Module{
this.headerCheckboxElement = null; // hold header select element

this.registerTableOption("selectable", "highlight"); //highlight rows on hover
this.registerTableOption("selectableMaxRows", true); //max number of selectable rows
this.registerTableOption("selectableRangeMode", "drag"); //highlight rows on hover
this.registerTableOption("selectableRollingSelection", true); //roll selection once maximum number of selectable rows is reached
this.registerTableOption("selectablePersistence", true); // maintain selection when table view is updated
Expand All @@ -31,6 +32,7 @@ class SelectRow extends Module{
}

initialize(){
this.deprecatedOptionsCheck();
if(this.table.options.selectable !== false){
this.subscribe("row-init", this.initializeRow.bind(this));
this.subscribe("row-deleting", this.rowDeleted.bind(this));
Expand All @@ -42,6 +44,12 @@ class SelectRow extends Module{
}
}
}

deprecatedOptionsCheck(){
if (typeof this.table.options.selectable !== "undefined" && Number.isInteger(this.table.options.selectable)) {
this.deprecationCheckMsg("selectable", "Please use selectableMaxRows to set the max number of selectable rows (selectable can still be used with non-numeric options).");
}
}

rowRetrieve(type, prevValue){
return type === "selected" ? this.selectedRows : prevValue;
Expand Down Expand Up @@ -247,8 +255,13 @@ class SelectRow extends Module{
//select an individual row
_selectRow(rowInfo, silent, force){
//handle max row count
if(!isNaN(this.table.options.selectable) && this.table.options.selectable !== true && !force){
if(this.selectedRows.length >= this.table.options.selectable){
var selectableMaxRows = this.table.options.selectable;
// For backward compatibility, we check table.options.selectable first.
if (!Number.isInteger(selectableMaxRows)) {
selectableMaxRows = this.table.options.selectableMaxRows;
}
if(Number.isInteger(selectableMaxRows) && !force){
if(this.selectedRows.length >= selectableMaxRows){
if(this.table.options.selectableRollingSelection){
this._deselectRow(this.selectedRows[0]);
}else{
Expand Down