Skip to content

Commit 89d8026

Browse files
authored
feat(next/antd): add options param in SelectTable onChange props (#2842)
1 parent 28a5853 commit 89d8026

File tree

7 files changed

+39
-34
lines changed

7 files changed

+39
-34
lines changed

packages/antd/docs/components/SelectTable.md

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export default () => {
8686
x-component-props={{
8787
bordered: false,
8888
showSearch: true,
89-
optionFilterProp: 'name',
9089
optionAsValue: true,
9190
}}
9291
enum={[

packages/antd/docs/components/SelectTable.zh-CN.md

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export default () => {
8686
x-component-props={{
8787
bordered: false,
8888
showSearch: true,
89-
optionFilterProp: 'name',
9089
optionAsValue: true,
9190
}}
9291
enum={[

packages/antd/src/select-table/index.tsx

+12-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface ISelectTableProps extends TableProps<any> {
3030
filterOption?: IFilterOption
3131
filterSort?: IFilterSort
3232
onSearch?: (keyword: string) => void
33-
onChange?: (value: any) => void
33+
onChange?: (value: any, options: any) => void
3434
value?: any
3535
}
3636

@@ -146,15 +146,17 @@ export const SelectTable: ComposedSelectTable = observer((props) => {
146146
if (readOnly) {
147147
return
148148
}
149-
let outputValue = optionAsValue
150-
? records.map((item) => {
151-
const validItem = { ...item }
152-
delete validItem['__formily_key__']
153-
return validItem
154-
})
155-
: selectedRowKeys
156-
outputValue = mode === 'single' ? outputValue[0] : outputValue
157-
onChange?.(outputValue)
149+
let outputOptions = records.map((item) => {
150+
const validItem = { ...item }
151+
delete validItem['__formily_key__']
152+
return validItem
153+
})
154+
let outputValue = optionAsValue ? outputOptions : selectedRowKeys
155+
if (mode === 'single') {
156+
outputValue = outputValue[0]
157+
outputOptions = outputOptions[0]
158+
}
159+
onChange?.(outputValue, outputOptions)
158160
}
159161

160162
const onRowClick = (record) => {

packages/next/docs/components/SelectTable.md

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export default () => {
8686
x-component-props={{
8787
hasBorder: false,
8888
showSearch: true,
89-
optionFilterProp: 'name',
9089
optionAsValue: true,
9190
}}
9291
enum={[

packages/next/docs/components/SelectTable.zh-CN.md

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export default () => {
8686
x-component-props={{
8787
hasBorder: false,
8888
showSearch: true,
89-
optionFilterProp: 'name',
9089
optionAsValue: true,
9190
}}
9291
enum={[

packages/next/src/select-table/index.tsx

+14-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export interface ISelectTableColumnProps extends ColumnProps {
2020
key: React.ReactText
2121
}
2222

23-
export interface ISelectTableProps extends Omit<TableProps, 'primaryKey'> {
23+
export interface ISelectTableProps
24+
extends Omit<TableProps, 'primaryKey' | 'onChange'> {
2425
mode?: 'multiple' | 'single'
2526
dataSource?: any[]
2627
optionAsValue?: boolean
@@ -30,7 +31,7 @@ export interface ISelectTableProps extends Omit<TableProps, 'primaryKey'> {
3031
filterOption?: IFilterOption
3132
filterSort?: IFilterSort
3233
onSearch?: (keyword: string) => void
33-
onChange?: (value: any) => void
34+
onChange?: (value: any, options: any) => void
3435
value?: any
3536
rowSelection?: TableProps['rowSelection'] & {
3637
checkStrictly?: boolean
@@ -149,15 +150,17 @@ export const SelectTable: ComposedSelectTable = observer((props) => {
149150
if (readOnly) {
150151
return
151152
}
152-
let outputValue = optionAsValue
153-
? records.map((item) => {
154-
const validItem = { ...item }
155-
delete validItem['__formily_key__']
156-
return validItem
157-
})
158-
: selectedRowKeys
159-
outputValue = mode === 'single' ? outputValue[0] : outputValue
160-
onChange?.(outputValue)
153+
let outputOptions = records.map((item) => {
154+
const validItem = { ...item }
155+
delete validItem['__formily_key__']
156+
return validItem
157+
})
158+
let outputValue = optionAsValue ? outputOptions : selectedRowKeys
159+
if (mode === 'single') {
160+
outputValue = outputValue[0]
161+
outputOptions = outputOptions[0]
162+
}
163+
onChange?.(outputValue, outputOptions)
161164
}
162165

163166
const onRowClick = (record) => {

packages/next/src/select-table/useCheckSlackly.tsx

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isArr } from '@formily/shared'
2+
13
/**
24
* 获取该字段Checkbox的indeterminate属性
35
* @param record 字段项
@@ -29,15 +31,17 @@ const getCheckedProps = (record: any, primaryKey: string, selected: any[]) => {
2931
* @param primaryKey 键名称
3032
* @returns 键值数组集合
3133
*/
32-
const getTreeKeys = (tree: any[] = [], primaryKey: string) =>
33-
tree.reduce(
34-
(prev, current) => [
35-
...prev,
36-
current[primaryKey],
37-
...getTreeKeys(current?.children, primaryKey),
38-
],
39-
[]
40-
)
34+
const getTreeKeys = (tree: any[], primaryKey: string) =>
35+
isArr(tree)
36+
? tree.reduce(
37+
(prev, current) => [
38+
...prev,
39+
current[primaryKey],
40+
...getTreeKeys(current?.children, primaryKey),
41+
],
42+
[]
43+
)
44+
: []
4145

4246
/**
4347
* 获取最终选中值(添加选中所有子元素的父元素,或移除未选中所有子元素的父元素)

0 commit comments

Comments
 (0)