8000 Tabulator: allow to set a maximum number of selectable rows by maximlt · Pull Request #2791 · holoviz/panel · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
allow to set the maximum number of rows selectable
  • Loading branch information
maximlt committed Sep 28, 2021
commit 18a7fa7424f4a11b15690411d3fe3122889be17e
12 changes: 10 additions & 2 deletions panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ export class DataTabulatorView extends PanelHTMLBoxView {

getConfiguration(): any {
const pagination = this.model.pagination == 'remote' ? 'local': (this.model.pagination || false)
let selectable = !(typeof this.model.select_mode === 'boolean')
// selectable is true if select_mode is a string (one of 'checkbox', 'checkbox-single' and
// 'toggle'). False if it's a boolean or a number (integer on the python side).
let selectable = (typeof this.model.select_mode) === 'string'
const that = this
let configuration = {
...this.model.configuration,
Expand Down Expand Up @@ -587,7 +589,7 @@ export class DataTabulatorView extends PanelHTMLBoxView {
// Update model

rowClicked(e: any, row: any) {
if (this._selection_updating || this._initializing || this.model.select_mode !== true)
if (this._selection_updating || this._initializing || (typeof this.model.select_mode) === 'string' || this.model.select_mode === false)
return
let indices: number[] = []
const selected = this.model.source.selected
Expand All @@ -608,6 +610,12 @@ export class DataTabulatorView extends PanelHTMLBoxView {
indices.push(index)
else
indices.splice(indices.indexOf(index), 1)
// Remove the first selected indices when selectable is an int.
if (typeof this.model.select_mode === 'number') {
while (indices.length > this.model.select_mode) {
indices.shift()
}
}
const filtered = this._filter_selected(indices)
this.tabulator.deselectRow()
this.tabulator.selectRow(filtered)
Expand Down
6 changes: 4 additions & 2 deletions panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ class Tabulator(BaseTable):
row_height = param.Integer(default=30, doc="""
The height of each table row.""")

selectable = param.ObjectSelector(
default=True, objects=[True, False, 'checkbox', 'checkbox-single', 'toggle'], doc="""
selectable = param.ClassSelector(
default=True, class_=(bool, str, int), doc="""
Defines the selection mode of the Tabulator.

- True
Expand All @@ -747,6 +747,8 @@ class Tabulator(BaseTable):
Same as 'checkbox' but header does not alllow select/deselect all
- 'toggle'
Selection toggles when clicked
- int
The maximum number of selectable rows.
""")

selectable_rows = param.Callable(default=None, doc="""
Expand Down
0