Add selectionHeaderRenderer hook and make the width of the selection checkbox column configurable.
This commit is contained in:
@@ -19,4 +19,10 @@ Each column object has the following properties:
|
|||||||
|
|
||||||
To override the default table column headers you can override the `renderColumnHeader(column, idx)` method.
|
To override the default table column headers you can override the `renderColumnHeader(column, idx)` method.
|
||||||
|
|
||||||
|
To override only the selection header, provide a `selectionHeaderRenderer` function property. Return `null` or `undefined` to use the default select-all checkbox.
|
||||||
|
|
||||||
To override the default cell elements you can override the `renderItem(item, idx, columns, selected)` method.
|
To override the default cell elements you can override the `renderItem(item, idx, columns, selected)` method.
|
||||||
|
|
||||||
|
## Styling
|
||||||
|
|
||||||
|
- `--tp-table-checkbox-column-width`: Width of the checkbox selection column. Defaults to `40px`.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tp/tp-table",
|
"name": "@tp/tp-table",
|
||||||
"version": "1.5.0",
|
"version": "1.6.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "tp-table.js",
|
"main": "tp-table.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+1
-1
@@ -127,7 +127,7 @@ class TpTableItem extends BaseElement {
|
|||||||
.join(' ');
|
.join(' ');
|
||||||
|
|
||||||
if (this.selectable && this.selectionMode !== 'row-click') {
|
if (this.selectable && this.selectionMode !== 'row-click') {
|
||||||
colWidths = '40px ' + colWidths;
|
colWidths = 'var(--tp-table-checkbox-column-width, 40px) ' + colWidths;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$grid.style.gridTemplateColumns = colWidths;
|
this.$grid.style.gridTemplateColumns = colWidths;
|
||||||
|
|||||||
+16
-1
@@ -213,6 +213,14 @@ export class TpTable extends DomQuery(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderSelectionHeader() {
|
renderSelectionHeader() {
|
||||||
|
if (typeof this.selectionHeaderRenderer === 'function') {
|
||||||
|
const rendered = this.selectionHeaderRenderer(this);
|
||||||
|
|
||||||
|
if (rendered !== null && rendered !== undefined) {
|
||||||
|
return rendered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return html`<tp-checkbox @toggled=${e => this._checkedChanged(e)}></tp-checkbox>`;
|
return html`<tp-checkbox @toggled=${e => this._checkedChanged(e)}></tp-checkbox>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,6 +279,7 @@ export class TpTable extends DomQuery(LitElement) {
|
|||||||
|
|
||||||
sorting: { type: Object },
|
sorting: { type: Object },
|
||||||
selectable: { type: Boolean },
|
selectable: { type: Boolean },
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls how rows are selected when `selectable` is true.
|
* Controls how rows are selected when `selectable` is true.
|
||||||
* - "checkbox" (default): header + per-row checkboxes; multi-select.
|
* - "checkbox" (default): header + per-row checkboxes; multi-select.
|
||||||
@@ -279,6 +288,12 @@ export class TpTable extends DomQuery(LitElement) {
|
|||||||
* from the last clicked row. No checkbox column is rendered.
|
* from the last clicked row. No checkbox column is rendered.
|
||||||
*/
|
*/
|
||||||
selectionMode: { type: String },
|
selectionMode: { type: String },
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional renderer for the selection header cell. Return null or
|
||||||
|
* undefined to use the default select-all checkbox.
|
||||||
|
*/
|
||||||
|
selectionHeaderRenderer: { attribute: false },
|
||||||
items: { type: Array },
|
items: { type: Array },
|
||||||
columnMoveHandle: { type: String },
|
columnMoveHandle: { type: String },
|
||||||
_selItems: { state: true },
|
_selItems: { state: true },
|
||||||
@@ -392,7 +407,7 @@ export class TpTable extends DomQuery(LitElement) {
|
|||||||
|
|
||||||
_updateColumns() {
|
_updateColumns() {
|
||||||
this.$.tableHeader.style.gridTemplateColumns = this._updateColumnWidths(
|
this.$.tableHeader.style.gridTemplateColumns = this._updateColumnWidths(
|
||||||
this._hasCheckboxColumn ? ['40px'] : []
|
this._hasCheckboxColumn ? ['var(--tp-table-checkbox-column-width, 40px)'] : []
|
||||||
).join(' ');
|
).join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user