Skip to content

Commit

Permalink
fix: 修复表格调整排序信息未保存问题 Close: baidu#8585 (baidu#9618)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Feb 24, 2024
1 parent 4c3321e commit 58feb0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/amis-core/src/store/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ export const TableStore = iRendererStore
.named('TableStore')
.props({
columns: types.array(Column),
columnsKey: '',
rows: types.array(Row),
selectedRows: types.array(types.reference(Row)),
expandedRows: types.array(types.string),
Expand Down Expand Up @@ -1105,6 +1106,7 @@ export const TableStore = iRendererStore
(self.tableLayout = config.tableLayout);

if (config.columns && Array.isArray(config.columns)) {
self.columnsKey = getPersistDataKey(config.columns);
let columns: Array<SColumn> = config.columns
.map(column => {
if (
Expand All @@ -1123,7 +1125,7 @@ export const TableStore = iRendererStore
.filter(column => column);

// 更新列顺序,afterCreate生命周期中更新columns不会触发组件的render
const key = getPersistDataKey(columns);
const key = self.columnsKey;
const data = localStorage.getItem(key);
let tableMetaData = null;

Expand Down Expand Up @@ -1841,7 +1843,7 @@ export const TableStore = iRendererStore
* 前端持久化记录列排序,查询字段,显示列信息
*/
function persistSaveToggledColumns() {
const key = getPersistDataKey(self.columnsData);
const key = self.columnsKey;

localStorage.setItem(
key,
Expand Down Expand Up @@ -1947,7 +1949,7 @@ export const TableStore = iRendererStore
if (!isAlive(self)) {
return;
}
const key = getPersistDataKey(self.columnsData);
const key = self.columnsKey;
const data = localStorage.getItem(key);

if (data) {
Expand Down
1 change: 1 addition & 0 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,7 @@ export default class Table extends React.Component<TableProps, object> {
const {store} = this.props;

store.updateColumns(columns);
store.persistSaveToggledColumns();
}

renderAutoFilterForm(): React.ReactNode {
Expand Down

0 comments on commit 58feb0b

Please sign in to comment.