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); options.params['filter'] = JSON.stringify(filter);
} }
if (sorter) { if (sorter) {
sort = [];
const arr = Array.isArray(sorter) ? sorter : [sorter]; const arr = Array.isArray(sorter) ? sorter : [sorter];
arr.forEach(({ order, field }) => { arr.forEach(({ order, field }) => {
if (order === 'descend') { if (order === 'descend') {

View File

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

View File

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