diff --git a/src/renderers/CRUD.tsx b/src/renderers/CRUD.tsx index 357d73579..20341acd5 100644 --- a/src/renderers/CRUD.tsx +++ b/src/renderers/CRUD.tsx @@ -465,12 +465,16 @@ export default class CRUD extends React.Component { } componentDidMount() { - const {store, autoGenerateFilter} = this.props; + const {store, autoGenerateFilter, columns} = this.props; if (this.props.perPage) { store.changePage(store.page, this.props.perPage); } + // 没有 filter 或者 没有展示 filter 时应该默认初始化一次, + // 否则就应该等待 filter 里面的表单初始化的时候才初始化 + // 另外autoGenerateFilter时,table 里面会单独处理这块逻辑 + // 所以这里应该忽略 autoGenerateFilter 情况 if ( (!this.props.filter || (store.filterTogggable && !store.filterVisible)) && !autoGenerateFilter diff --git a/src/renderers/Table/index.tsx b/src/renderers/Table/index.tsx index 8e4122a98..ab424c955 100644 --- a/src/renderers/Table/index.tsx +++ b/src/renderers/Table/index.tsx @@ -500,7 +500,7 @@ export default class Table extends React.Component { this.handleMouseLeave = this.handleMouseLeave.bind(this); this.subFormRef = this.subFormRef.bind(this); this.handleColumnToggle = this.handleColumnToggle.bind(this); - this.renderAutoFilterForm = this.renderAutoFilterForm.bind(this); + this.updateAutoFillHeight = this.updateAutoFillHeight.bind(this); const { @@ -614,6 +614,19 @@ export default class Table extends React.Component { window.addEventListener('resize', this.affixDetect); this.updateAutoFillHeight(); window.addEventListener('resize', this.updateAutoFillHeight); + + const {store, autoGenerateFilter, onSearchableFromInit} = this.props; + + // autoGenerateFilter 开启后 + // 如果没有一个 searchable 的 column crud 就不会初始化加载 + // 所以这里加个判断默认初始加载一次 + if ( + autoGenerateFilter && + !store.searchableColumns.length && + onSearchableFromInit + ) { + onSearchableFromInit({}); + } } /** @@ -1470,7 +1483,13 @@ export default class Table extends React.Component { activedSearchableColumns.forEach((column, index) => { groupedSearchableColumns[index % 3].body.push({ - ...column.searchable, + ...(column.searchable === true + ? { + type: 'input-text', + name: column.name, + label: column.label + } + : column.searchable), name: column.searchable?.name ?? column.name, label: column.searchable?.label ?? column.label, mode: 'horizontal' diff --git a/src/store/table.ts b/src/store/table.ts index da848c329..15c473ee7 100644 --- a/src/store/table.ts +++ b/src/store/table.ts @@ -518,9 +518,7 @@ export const TableStore = iRendererStore } function getSearchableColumns() { - return self.columns.filter( - column => column.searchable && isObject(column.searchable) - ); + return self.columns.filter(column => column.searchable); } return {