Skip to content

Commit 86c53dd

Browse files
tmorehousejacobmllr95
authored andcommitted
feat(b-table): add selectAllRows() and clearSelected() to thead/tfoot slot scopes (addresses bootstrap-vue#3901) (bootstrap-vue#3907)
* feat(b-table): add `selectAllRows()` and `clearSelected()` to thead slot scopes * Update mixin-thead.js * Update README.md
1 parent 2c8bd23 commit 86c53dd

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/components/table/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,11 +1070,13 @@ footer cells that do not have an explicit scoped slot provided.
10701070
The slots can be optionally scoped (`data` in the above example), and will have the following
10711071
properties:
10721072

1073-
| Property | Type | Description |
1074-
| -------- | ------ | ------------------------------------------------------------- |
1075-
| `column` | String | The fields's `key` value |
1076-
| `field` | Object | the field's object (from the `fields` prop) |
1077-
| `label` | String | The fields label value (also available as `data.field.label`) |
1073+
| Property | Type | Description |
1074+
| --------------- | ------ | ----------------------------------------------------------------------------------------- |
1075+
| `column` | String | The fields's `key` value |
1076+
| `field` | Object | the field's object (from the `fields` prop) |
1077+
| `label` | String | The fields label value (also available as `data.field.label`) |
1078+
| `selectAllRows` | Method | Select all rows (applicable if the table is in [`selectable`](#row-select-support) mode |
1079+
| `clearSelected` | Method | Unselect all rows (applicable if the table is in [`selectable`](#row-select-support) mode |
10781080

10791081
When placing inputs, buttons, selects or links within a `HEAD[...]` or `FOOT[...]` slot, note that
10801082
`head-clicked` event will not be emitted when the input, select, textarea is clicked (unless they
@@ -1138,10 +1140,12 @@ rather than native browser table child elements.
11381140

11391141
Slot `thead-top` can be optionally scoped, receiving an object with the following properties:
11401142

1141-
| Property | Type | Description |
1142-
| --------- | ------ | ----------------------------------------------------------------------------- |
1143-
| `columns` | Number | The number of columns in the rendered table |
1144-
| `fields` | Array | Array of field definition objects (normalized to the array of objects format) |
1143+
| Property | Type | Description |
1144+
| --------------- | ------ | ----------------------------------------------------------------------------------------- |
1145+
| `columns` | Number | The number of columns in the rendered table |
1146+
| `fields` | Array | Array of field definition objects (normalized to the array of objects format) |
1147+
| `selectAllRows` | Method | Select all rows (applicable if the table is in [`selectable`](#row-select-support) mode |
1148+
| `clearSelected` | Method | Unselect all rows (applicable if the table is in [`selectable`](#row-select-support) mode |
11451149

11461150
## Custom empty and emptyfiltered rendering via slots
11471151

src/components/table/helpers/mixin-thead.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export default {
5555
return h()
5656
}
5757

58+
// Refernce to `selectAllRows` and `clearSelected()`, if table is Selectable
59+
const selectAllRows = this.isSelectable ? this.selectAllRows : () => {}
60+
const clearSelected = this.isSelectable ? this.clearSelected : () => {}
61+
5862
// Helper function to generate a field <th> cell
5963
const makeCell = (field, colIndex) => {
6064
let ariaLabel = null
@@ -116,7 +120,10 @@ export default {
116120
label: field.label,
117121
column: field.key,
118122
field,
119-
isFoot
123+
isFoot,
124+
// Add in row select methods
125+
selectAllRows,
126+
clearSelected
120127
})
121128
if (!slot) {
122129
// need to check if this will work
@@ -135,7 +142,10 @@ export default {
135142
} else {
136143
const scope = {
137144
columns: fields.length,
138-
fields: fields
145+
fields: fields,
146+
// Add in row select methods
147+
selectAllRows,
148+
clearSelected
139149
}
140150
$trs.push(this.normalizeSlot('thead-top', scope) || h())
141151
$trs.push(h(BTr, { class: this.theadTrClass }, $cells))

0 commit comments

Comments
 (0)