Skip to content

Commit

Permalink
fix: track state of visible components
Browse files Browse the repository at this point in the history
Some components would lose their state after applying search filter.
This bug is partially solved.
  • Loading branch information
uwla committed Nov 21, 2024
1 parent 4828bd0 commit ece3bcd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/components/DataTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,20 @@ export default defineComponent({
* The data filtered by search text
*/
dataFiltered() {
const { data, searchableColumns, search } = this
const { searchableColumns, search } = this

// assign key to track row
const data = this.data.map((value, index) => {
return {
...(value as Object),
_key: index,
};
})

if (isNullable(search)) {
return data
}

return data.filter(function(row: any) {
return searchableColumns.some(function(column: Column) {
return column.searchFunction(row, search, column.key)
Expand Down
15 changes: 10 additions & 5 deletions src/components/Table/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@
</tr>

<!-- NON-EMPTY BODY -->
<tr v-for="(data, i) in dataDisplayed" :key="i">
<td v-for="(column, j) in columns" :key="j">
<component :is="column.component"
v-bind="{ data, ...column.componentProps }"
@userEvent="emitUserEvent" />
<tr v-for="data in dataDisplayed" :key="data._key">

Check failure on line 43 in src/components/Table/Table.vue

View workflow job for this annotation

GitHub Actions / build (16.x)

'data' is of type 'unknown'.

Check failure on line 43 in src/components/Table/Table.vue

View workflow job for this annotation

GitHub Actions / build (18.x)

'data' is of type 'unknown'.

Check failure on line 43 in src/components/Table/Table.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

'data' is of type 'unknown'.
<keep-alive>
<td v-for="(column, j) in columns"
:key="'c' + data._key + 'c' + j"

Check failure on line 46 in src/components/Table/Table.vue

View workflow job for this annotation

GitHub Actions / build (16.x)

'data' is of type 'unknown'.

Check failure on line 46 in src/components/Table/Table.vue

View workflow job for this annotation

GitHub Actions / build (18.x)

'data' is of type 'unknown'.

Check failure on line 46 in src/components/Table/Table.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

'data' is of type 'unknown'.
>
<component
:is="column.component"
v-bind="{ data, ...column.componentProps }"
@userEvent="emitUserEvent" />
</td>
</keep-alive>
</tr>
</tbody>

Expand Down

0 comments on commit ece3bcd

Please sign in to comment.