提交 8e4f486f 作者: 无木

feat(table): add updateTableDataRecord method

添加updateTableDataRecord以便可以根据指定的rowKey来直接更新行数据而无需reload
上级 5212ea79
...@@ -129,6 +129,7 @@ ...@@ -129,6 +129,7 @@
getDataSourceRef, getDataSourceRef,
getDataSource, getDataSource,
setTableData, setTableData,
updateTableDataRecord,
fetch, fetch,
getRowKey, getRowKey,
reload, reload,
...@@ -265,6 +266,7 @@ ...@@ -265,6 +266,7 @@
deleteSelectRowByKey, deleteSelectRowByKey,
setPagination, setPagination,
setTableData, setTableData,
updateTableDataRecord,
redoHeight, redoHeight,
setSelectedRowKeys, setSelectedRowKeys,
setColumns, setColumns,
......
...@@ -149,6 +149,26 @@ export function useDataSource( ...@@ -149,6 +149,26 @@ export function useDataSource(
return dataSourceRef.value[index]; 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) { async function fetch(opt?: FetchParams) {
const { api, searchInfo, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } = const { api, searchInfo, fetchSetting, beforeFetch, afterFetch, useSearchForm, pagination } =
unref(propsRef); unref(propsRef);
...@@ -255,6 +275,7 @@ export function useDataSource( ...@@ -255,6 +275,7 @@ export function useDataSource(
fetch, fetch,
reload, reload,
updateTableData, updateTableData,
updateTableDataRecord,
handleTableChange, handleTableChange,
}; };
} }
...@@ -120,6 +120,9 @@ export function useTable(tableProps?: Props): [ ...@@ -120,6 +120,9 @@ export function useTable(tableProps?: Props): [
updateTableData: (index: number, key: string, value: any) => { updateTableData: (index: number, key: string, value: any) => {
return getTableInstance().updateTableData(index, key, value); return getTableInstance().updateTableData(index, key, value);
}, },
updateTableDataRecord: (rowKey: string | number, record: Recordable) => {
return getTableInstance().updateTableDataRecord(rowKey, record);
},
getRowSelection: () => { getRowSelection: () => {
return toRaw(getTableInstance().getRowSelection()); return toRaw(getTableInstance().getRowSelection());
}, },
......
...@@ -94,6 +94,7 @@ export interface TableActionType { ...@@ -94,6 +94,7 @@ export interface TableActionType {
deleteSelectRowByKey: (key: string) => void; deleteSelectRowByKey: (key: string) => void;
setPagination: (info: Partial<PaginationProps>) => void; setPagination: (info: Partial<PaginationProps>) => void;
setTableData: <T = Recordable>(values: T[]) => void; setTableData: <T = Recordable>(values: T[]) => void;
updateTableDataRecord: (rowKey: string | number, record: Recordable) => Recordable | void;
getColumns: (opt?: GetColumnsParams) => BasicColumn[]; getColumns: (opt?: GetColumnsParams) => BasicColumn[];
setColumns: (columns: BasicColumn[] | string[]) => void; setColumns: (columns: BasicColumn[] | string[]) => void;
getDataSource: <T = Recordable>() => T[]; getDataSource: <T = Recordable>() => T[];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论