Skip to content

Commit 2cb7365

Browse files
szintaariellalgilmoremaradwan26
authored
feat(datatable): select all buttion in wc batch actions (#20419)
Co-authored-by: Ariella Gilmore <ariellalgilmore@gmail.com> Co-authored-by: Mahmoud <132728978+maradwan26@users.noreply.github.com>
1 parent bda1bd9 commit 2cb7365

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

packages/web-components/src/components/data-table/stories/data-table-batch-actions.stories.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright IBM Corp. 2019, 2023
2+
* Copyright IBM Corp. 2019, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -83,7 +83,7 @@ export const Default = {
8383
>
8484
8585
<cds-table-toolbar slot="toolbar">
86-
<cds-table-batch-actions ?active="true">
86+
<cds-table-batch-actions total-rows-count="6">
8787
<cds-button data-context="data-table"
8888
>Delete
8989
${iconLoader(TrashCan, {

packages/web-components/src/components/data-table/table-batch-actions.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
2-
* Copyright IBM Corp. 2019, 2023
2+
* Copyright IBM Corp. 2019, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { LitElement, html } from 'lit';
8+
import { LitElement, html, nothing } from 'lit';
99
import { property } from 'lit/decorators.js';
1010
import { prefix } from '../../globals/settings';
1111
import styles from './data-table.scss?lit';
@@ -16,6 +16,7 @@ import { carbonElement as customElement } from '../../globals/decorators/carbon-
1616
*
1717
* @element cds-table-batch-actions
1818
* @fires cds-table-batch-actions-cancel-clicked - The custom event fired after the Cancel button is clicked.
19+
* @fires cds-table-batch-actions-select-all-clicked - The custom event fired after the Select all button is clicked.
1920
*/
2021

2122
@customElement(`${prefix}-table-batch-actions`)
@@ -31,6 +32,18 @@ class CDSTableBatchActions extends LitElement {
3132
);
3233
}
3334

35+
/**
36+
* Handles `click` event on the Select all button.
37+
*/
38+
private _handleSelectAll() {
39+
this.dispatchEvent(
40+
new CustomEvent(CDSTableBatchActions.eventClickSelectAll, {
41+
bubbles: true,
42+
composed: true,
43+
})
44+
);
45+
}
46+
3447
/**
3548
* `true` if this batch actions bar should be active.
3649
*/
@@ -51,6 +64,14 @@ class CDSTableBatchActions extends LitElement {
5164
@property({ type: Number, attribute: 'selected-rows-count' })
5265
selectedRowsCount = 0;
5366

67+
/**
68+
* Numeric representation of the total number of items in a table.
69+
* This number is used in the select all button text
70+
* This property controls the rendering of the Select all button
71+
*/
72+
@property({ type: Number, attribute: 'total-rows-count' })
73+
totalRowsCount = 0;
74+
5475
/**
5576
* The table size.
5677
*/
@@ -119,7 +140,9 @@ class CDSTableBatchActions extends LitElement {
119140
const {
120141
formatSelectedItemsCount,
121142
selectedRowsCount,
143+
totalRowsCount,
122144
_handleCancel: handleCancel,
145+
_handleSelectAll: handleSelectAll,
123146
size,
124147
} = this;
125148

@@ -130,6 +153,18 @@ class CDSTableBatchActions extends LitElement {
130153
<p class="${prefix}--batch-summary__para">
131154
${formatSelectedItemsCount({ count: selectedRowsCount })}
132155
</p>
156+
${totalRowsCount > 0
157+
? html`
158+
<span class="${prefix}--batch-summary__divider">|</span>
159+
<button
160+
class="${prefix}--btn ${prefix}--btn--primary ${prefix}--batch-summary__select-all"
161+
@click=${handleSelectAll}>
162+
<slot name="select-all-button-content"
163+
>Select all (${totalRowsCount})</slot
164+
>
165+
</button>
166+
`
167+
: nothing}
133168
</div>
134169
135170
<div class="${prefix}--action-list">
@@ -160,6 +195,13 @@ class CDSTableBatchActions extends LitElement {
160195
return `${prefix}-table-batch-actions-cancel-clicked`;
161196
}
162197

198+
/**
199+
* The name of the custom event fired after the Select all button is clicked.
200+
*/
201+
static get eventClickSelectAll() {
202+
return `${prefix}-table-batch-actions-select-all-clicked`;
203+
}
204+
163205
static styles = styles;
164206
}
165207

0 commit comments

Comments
 (0)