fix: sorter for datetime and number

This commit is contained in:
chenos 2021-03-28 21:08:54 +08:00
parent 0900296ea3
commit 611ce0d759
3 changed files with 6 additions and 1 deletions

View File

@ -65,6 +65,7 @@ class ApiClient {
options.params['filter'] = JSON.stringify(filter);
}
if (sorter) {
sort = [];
const arr = Array.isArray(sorter) ? sorter : [sorter];
arr.forEach(({ order, field }) => {
if (order === 'descend') {

View File

@ -221,7 +221,7 @@ export function Table(props: any) {
params,
} = useRequest(
(params = {}, ...args) => {
const { current, pageSize, sorter, filter, ...restParams } = params;
const { current, pageSize, sorter, filter, ...restParams } = params as any;
console.log('paramsparamsparamsparamsparams', params, args);
return api
.resource(resourceName)
@ -472,6 +472,7 @@ export function Table(props: any) {
columns={fields2columns(fields, { associatedKey, refresh })}
pagination={false}
onChange={(pagination, filters, sorter, extra) => {
console.log({sorter});
run({ ...params[0], sorter });
}}
expandable={expandable}

View File

@ -97,6 +97,9 @@ export function fields2columns(fields = [], ctx: any = {}) {
if (!field.dataIndex) {
field.dataIndex = field.name.split('.');
}
if (['datetime', 'number'].includes(field.interface)) {
field.sorter = true;
}
field.render = (value, record, index) =>
field.interface === 'sort' ? (
<DragHandle />