Skip to content

Commit fa32398

Browse files
committed
fix: do not show batch actions if no rows
1 parent 7909f7e commit fa32398

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/components/CvDataTable/CvDataTable.stories.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ const testData = ref([
2121
{ index:"6", name:"Fortran", year:1957, oo:"No", purpose:"Engineering applications", standard:"ANSI", desc: "Fortran was originally developed by IBM in the 1950s for scientific and engineering applications, and subsequently came to dominate scientific computing."},
2222
{ index:"7", name:"Go", year:2009, oo:"Maybe", purpose:"Networked applications", standard:"Go Spec", desc: "Go's designers were primarily motivated by their shared dislike of C++."},
2323
]);
24+
const sortOpts = ref({index: "0", order: "none", name: "name"})
2425
function sortTestData(opts) {
2526
action('sort')(opts)
27+
sortOpts.value = opts
2628
if (opts.order === 'none')
2729
return testData.value.sort((a, b) => a.index.localeCompare(b.index, 'en', { sensitivity: 'base' }));
2830
let direction = 1
@@ -32,6 +34,14 @@ function sortTestData(opts) {
3234
else if (opts.name === 'year')
3335
return testData.value.sort((a, b) => direction * (a.year - b.year));
3436
}
37+
// duplicate the test data
38+
const originalTestData = ref(JSON.parse(JSON.stringify(testData.value)))
39+
function searchTestData(opts) {
40+
action('search')(opts)
41+
if (!opts) testData.value = JSON.parse(JSON.stringify(originalTestData.value))
42+
else testData.value = originalTestData.value.filter(data => data.name.indexOf(opts) > -1)
43+
return sortTestData(sortOpts.value)
44+
}
3545

3646
<Meta title={`${sbCompPrefix}/CvDataTable`} component={CvDataTable} />
3747

@@ -59,7 +69,7 @@ setup() {
5969
template: undefined},
6070
trashIcon: TrashCanIcon,
6171
onSort: sortTestData,
62-
onSearch: action('search'),
72+
onSearch: searchTestData,
6373
onRowSelectChange: action('row-select-change'),
6474
onRowSelectChanges: action('row-select-changes'),
6575
onOverflowMenuClick: action('overflow-menu-click'),
@@ -77,6 +87,7 @@ setup() {
7787
skeletonTitle: args.title,
7888
skeletonHelper: args.helperText,
7989
testData,
90+
originalTestData
8091
};
8192
},
8293
// And then the `args` are bound to your component with `v-bind="args"`
@@ -135,6 +146,7 @@ const expandingRowsTemplate = defaultTemplate.replace(
135146
"<!-- Add optional expanding data here -->",
136147
`<template #expandedContent>{{row.desc}}</template>`)
137148
.replace('@search="onSearch"', '')
149+
.replace('testData', 'originalTestData')
138150
const skeletonTemplate = `
139151
<cv-data-table-skeleton
140152
:columns="skeletonCols"
@@ -160,7 +172,10 @@ const skeletonTemplate = `
160172
- Sorting, filtering and pagination are the responsibility of the component user. This component raises events to facilitate this.
161173
For example the test data is sorted like this but this is very specific to this data. Users will need to provide their own sort and filtering.
162174
```javascript
175+
// sort example
176+
const sortOpts = ref({index: "0", order: "none", name: "name"})
163177
function sortTestData(opts) {
178+
sortOpts.value = opts // remember this so it can be used in filtering
164179
if (opts.order === 'none')
165180
return testData.value.sort((a, b) => a.index.localeCompare(b.index, 'en', { sensitivity: 'base' }));
166181
let direction = 1
@@ -170,6 +185,12 @@ const skeletonTemplate = `
170185
else if (opts.name === 'year')
171186
return testData.value.sort((a, b) => direction * (a.year - b.year));
172187
}
188+
// filter example
189+
function searchTestData(opts) {
190+
if (!opts) testData.value = allData.value
191+
else testData.value = allData.value.filter(data => data.name.indexOf(opts) > -1)
192+
return sortTestData(sortOpts.value)
193+
}
173194
```
174195
- The search bar appears only if the search event is listened for.
175196

src/components/CvDataTable/CvDataTable.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ watch(
541541
() => store.state[uid.value],
542542
() => {
543543
const rows = store.rows(uid);
544-
headingChecked.value = dataRowsSelected.value.length === rows.length;
544+
headingChecked.value =
545+
rows.length > 0 && dataRowsSelected.value.length === rows.length;
545546
},
546547
{ deep: true }
547548
);

0 commit comments

Comments
 (0)