From 0a4508d0161692782b775fd6270dc8f6604f3986 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Mon, 6 Jun 2022 15:20:20 +0800 Subject: [PATCH] fix: Fix row hide in base table Get the latest hideable columns using the getter method Change-Id: I1d41e9671ea6943a2299d3608338a999789c7235 --- src/components/Tables/Base/index.jsx | 30 +++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/components/Tables/Base/index.jsx b/src/components/Tables/Base/index.jsx index 8dcceb6d..a9719971 100644 --- a/src/components/Tables/Base/index.jsx +++ b/src/components/Tables/Base/index.jsx @@ -124,7 +124,6 @@ export class BaseTable extends React.Component { constructor(props) { super(props); - this.state = { hideRow: getLocalStorageItem(`${this.useId}-${this.props.resourceName}`) || [], @@ -136,16 +135,6 @@ export class BaseTable extends React.Component { this.sortKey = props.defaultSortKey; this.sortOrder = props.defaultSortOrder; - this.hideableRow = props.columns - .filter((column) => !column.hidden) - .filter((column) => column.isHideable) - .map((column) => ({ - label: column.title, - value: this.getDataIndex(column.dataIndex) || column.key, - })); - - this.hideableColValues = this.hideableRow.map((item) => item.value); - this.suggestions = props.columns .filter((column) => column.search && column.dataIndex) .map((column) => ({ @@ -160,6 +149,16 @@ export class BaseTable extends React.Component { })); } + get hideableRows() { + return this.props.columns + .filter((column) => !column.hidden) + .filter((column) => column.isHideable) + .map((column) => ({ + label: column.title, + value: this.getDataIndex(column.dataIndex) || column.key, + })); + } + get useId() { const { user = {} } = toJS(this.props.rootStore) || {}; const { user: { id } = {} } = user || {}; @@ -238,11 +237,10 @@ export class BaseTable extends React.Component { }; handleRowHide = (columns) => { + const hideableColValues = this.hideableRows.map((item) => item.value); this.setState( { - hideRow: this.hideableColValues.filter( - (value) => !columns.includes(value) - ), + hideRow: hideableColValues.filter((value) => !columns.includes(value)), }, () => { setLocalStorageItem( @@ -815,7 +813,7 @@ export class BaseTable extends React.Component { const getHideColKeys = (cols) => { const results = []; - this.hideableRow.forEach((item) => { + this.hideableRows.forEach((item) => { if (cols.indexOf(item.value) === -1) { results.push(item.value); } @@ -826,7 +824,7 @@ export class BaseTable extends React.Component { return (