feat(table): add updateTableDataRecord method
添加updateTableDataRecord以便可以根据指定的rowKey来直接更新行数据而无需reload
| | |
| | | getDataSourceRef, |
| | | getDataSource, |
| | | setTableData, |
| | | updateTableDataRecord, |
| | | fetch, |
| | | getRowKey, |
| | | reload, |
| | |
| | | deleteSelectRowByKey, |
| | | setPagination, |
| | | setTableData, |
| | | updateTableDataRecord, |
| | | redoHeight, |
| | | setSelectedRowKeys, |
| | | setColumns, |
| | |
| | | return dataSourceRef.value[index]; |
| | | } |
| | | |
| | | function updateTableDataRecord( |
| | | rowKey: string | number, |
| | | record: Recordable |
| | | ): Recordable | undefined { |
| | | if (!dataSourceRef.value || dataSourceRef.value.length == 0) return; |
| | | const rowKeyName = unref(getRowKey); |
| | | if (typeof rowKeyName !== 'string') { |
| | | return; |
| | | } |
| | | const row = dataSourceRef.value.find( |
| | | (r) => Reflect.has(r, rowKeyName as string) && r[rowKeyName as string] === rowKey |
| | | ); |
| | | if (row) { |
| | | for (const field in row) { |
| | | if (Reflect.has(record, field)) row[field] = record[field]; |
| | | } |
| | | return row; |
| | | } |
| | | } |
| | | |
| | | async function fetch(opt?: FetchParams) { |
| | | const { api, searchInfo, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } = |
| | | unref(propsRef); |
| | |
| | | fetch, |
| | | reload, |
| | | updateTableData, |
| | | updateTableDataRecord, |
| | | handleTableChange, |
| | | }; |
| | | } |
| | |
| | | updateTableData: (index: number, key: string, value: any) => { |
| | | return getTableInstance().updateTableData(index, key, value); |
| | | }, |
| | | updateTableDataRecord: (rowKey: string | number, record: Recordable) => { |
| | | return getTableInstance().updateTableDataRecord(rowKey, record); |
| | | }, |
| | | getRowSelection: () => { |
| | | return toRaw(getTableInstance().getRowSelection()); |
| | | }, |
| | |
| | | deleteSelectRowByKey: (key: string) => void; |
| | | setPagination: (info: Partial<PaginationProps>) => void; |
| | | setTableData: <T = Recordable>(values: T[]) => void; |
| | | updateTableDataRecord: (rowKey: string | number, record: Recordable) => Recordable | void; |
| | | getColumns: (opt?: GetColumnsParams) => BasicColumn[]; |
| | | setColumns: (columns: BasicColumn[] | string[]) => void; |
| | | getDataSource: <T = Recordable>() => T[]; |