Support for row selection without checkboxes.
This commit is contained in:
+24
-4
@@ -71,10 +71,11 @@ class TpTableItem extends BaseElement {
|
||||
|
||||
render() {
|
||||
const { columns, item, selected } = this;
|
||||
const showCheckbox = this.selectable && this.selectionMode !== 'row-click';
|
||||
|
||||
return html`
|
||||
<div id="grid" class="wrap" part="row">
|
||||
${this.selectable ? html`
|
||||
${showCheckbox ? html`
|
||||
<div class="chk" part="chk">
|
||||
<tp-checkbox id="selectionChk" .checked=${selected} @click=${this._updateSelectionState}></tp-checkbox>
|
||||
</div>
|
||||
@@ -88,12 +89,23 @@ class TpTableItem extends BaseElement {
|
||||
`;
|
||||
}
|
||||
|
||||
updated(changes) {
|
||||
if (changes.has('selectionMode') || changes.has('selectable')) {
|
||||
if (this.selectionMode && this.selectionMode !== 'checkbox') {
|
||||
this.setAttribute('data-selection-mode', this.selectionMode);
|
||||
} else {
|
||||
this.removeAttribute('data-selection-mode');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
index: { type: Array },
|
||||
item: { type: Object, hasChanged: () => true },
|
||||
columns: { type: Array },
|
||||
selectable: { type: Boolean },
|
||||
selectionMode: { type: String },
|
||||
selected: { type: Boolean, reflect: true },
|
||||
};
|
||||
}
|
||||
@@ -103,10 +115,18 @@ class TpTableItem extends BaseElement {
|
||||
}
|
||||
|
||||
async updated(changes) {
|
||||
if (changes.has('columns') && Array.isArray(this.columns)) {
|
||||
let colWidths = this.columns.filter(col => col.required || col.visible).map(col => col.width).join(' ');
|
||||
const needsWidthRecalc =
|
||||
(changes.has('columns') && Array.isArray(this.columns)) ||
|
||||
changes.has('selectionMode') ||
|
||||
changes.has('selectable');
|
||||
|
||||
if (this.selectable) {
|
||||
if (needsWidthRecalc) {
|
||||
let colWidths = (this.columns || [])
|
||||
.filter(col => col.required || col.visible)
|
||||
.map(col => col.width)
|
||||
.join(' ');
|
||||
|
||||
if (this.selectable && this.selectionMode !== 'row-click') {
|
||||
colWidths = '40px ' + colWidths;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user