ahooks
Version:
react hooks library
36 lines (35 loc) • 1.47 kB
JavaScript
export const fieldAdapter = (field) => ({
getFieldInstance: (name) => field.getNames().includes(name),
setFieldsValue: field.setValues,
getFieldsValue: field.getValues,
resetFields: field.resetToDefault,
validateFields: (fields, callback) => {
field.validate(fields, callback);
},
});
export const resultAdapter = (result) => {
const tableProps = {
dataSource: result.tableProps.dataSource,
loading: result.tableProps.loading,
onSort: (dataIndex, order) => {
var _a;
result.tableProps.onChange({ current: result.pagination.current, pageSize: result.pagination.pageSize }, (_a = result.params[0]) === null || _a === void 0 ? void 0 : _a.filters, {
field: dataIndex,
order,
});
},
onFilter: (filterParams) => {
var _a;
result.tableProps.onChange({ current: result.pagination.current, pageSize: result.pagination.pageSize }, filterParams, (_a = result.params[0]) === null || _a === void 0 ? void 0 : _a.sorter);
},
};
const paginationProps = {
onChange: result.pagination.changeCurrent,
onPageSizeChange: result.pagination.changePageSize,
current: result.pagination.current,
pageSize: result.pagination.pageSize,
total: result.pagination.total,
};
return Object.assign(Object.assign({}, result), { tableProps,
paginationProps });
};