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

数据更新 页面不更新 #8367

Open
whqgo opened this issue Apr 28, 2024 · 1 comment
Open

数据更新 页面不更新 #8367

whqgo opened this issue Apr 28, 2024 · 1 comment

Comments

@whqgo
Copy link

whqgo commented Apr 28, 2024

const columns = useRef<any>([
    {
        key: 'sort',
        dataIndex: 'key',
        editable: false,
        width: 30,
    },
    {
        title: '序号',
        key: 'serial',
        dataIndex: 'serial',
        // editable: false,
        width: '60px',
        // render: (_: any, __: any, index: number) => index + 1, // 使用 index + 1 作为序号值
    },
    {
        title: '字段名称',
        dataIndex: 'lable',
        width: '30%',
    },
    {
        title: '是否显示',
        dataIndex: 'visible',
        valueType: 'checkbox',
        width: '30%',
        renderFormItem: (_: any, itemRecord: any) => {
            // 自定义复选框的渲染
            return <Checkbox onChange={(e) => {
                console.log(itemRecord, "===record===");
              
                // record
                setDataSource((dataSource: any) => {
                    let _dataSource = cloneDeep(dataSource)
                    let recordfind = _dataSource.find((f: any) => f.id === itemRecord.record.id)
                    recordfind.visible = false
                    console.log(_dataSource, "===_dataSource====");

                    return _dataSource
                })

            }} checked={itemRecord.record.visible}>{itemRecord.record.visible}</Checkbox>
        }
    },

    {
        title: '操作',
        valueType: 'option',
        width: 250,
        render: () => {
            return null;
        },
    },
])

我修改了 数据 但是页面并没有更新

@whqgo
Copy link
Author

whqgo commented Apr 28, 2024

                        headerTitle=""
                        columns={columns.current}
                        rowKey="id"
                        scroll={{
                            x: 960,
                        }}
                        value={dataSource}
                        onChange={(e)=>{
                            console.log(e,"=====EditableProTable======onChange=======");
                            debugger
                            
                            setDataSource(()=>e)
                        }}
                        recordCreatorProps={false}
                        // recordCreatorProps={{
                        //     newRecordType: 'dataSource',
                        //     // position: 'top',
                        //     // 设置按钮文案
                        //     creatorButtonText: '新增一行',
                        //     record: () => ({
                        //         id: Date.now(),
                        //     }),
                        // }}
                        // toolBarRender={() => {
                        //     return [
                        //         <Button
                        //             type="primary"
                        //             key="save"
                        //             onClick={() => {
                        //                 // dataSource 就是当前数据,可以调用 api 将其保存
                        //                 console.log(dataSource);
                        //             }}
                        //         >
                        //             保存数据
                        //         </Button>,
                        //     ];
                        // }}
                        editable={{
                            type: 'multiple',
                            editableKeys,
                            actionRender: (row, config, defaultDoms) => {
                                return [defaultDoms.delete];
                            },
                            onValuesChange: (record, recordList) => {
                                console.log(record, "==onValuesChange=record===");
                                console.log(recordList, "==onValuesChange=recordList===");
                                
                                setDataSource((data)=>{


                                    return data
                                });
                            },
                            onChange: setEditableRowKeys,
                        }}
                        // pagination={false}
                        components={{
                            body: {
                                row: RowH,
                            },
                        }}
                    />
                </SortableContext>
            </DndContext>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant