Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(table): add support of custom render serch form #7307

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions packages/table/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@
polling,
tooltip,
revalidateOnFocus = false,
searchFormRender,
...rest
} = props;
const { wrapSSR, hashId } = useStyle(props.defaultClassName);
Expand Down Expand Up @@ -843,8 +844,8 @@
return action.loading;
}, [action.loading]);

const searchNode =
search === false && type !== 'form' ? null : (
const searchNode = useMemo(() => {
const node = search === false && type !== 'form' ? null : (
<FormRender<T, U>
pagination={pagination}
beforeSearchSubmit={beforeSearchSubmit}
Expand All @@ -867,6 +868,26 @@
/>
);

if (searchFormRender && node) {
return <>{searchFormRender(props, node)}</>;
} else {
return node;
}
}, [
beforeSearchSubmit,
formRef,
ghost,
loading,
manualRequest,
onFormSearchSubmit,
pagination,
props,
propsColumns,
search,
searchFormRender,
type,
])
Fixed Show fixed Hide fixed

const selectedRows = useMemo(
() => selectedRowKeys?.map((key) => preserveRecordsRef.current?.get(key)),
[selectedRowKeys],
Expand Down
8 changes: 8 additions & 0 deletions packages/table/src/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ export type ProTableProps<DataSource, U, ValueType = 'text'> = {
dataSource: DataSource[],
) => React.ReactNode;

/**
* @name 渲染搜索表单
*/
searchFormRender?: (
props: ProTableProps<DataSource, U, ValueType>,
defaultDom: JSX.Element,
) => React.ReactNode;

/** @name 一个获得 dataSource 的方法 */
request?: (
params: U & {
Expand Down
Loading