我正在尝试按帖子名称而不是ID检索帖子列表。默认情况下,dataProvider在sort常量中将字段param设置为'id'。我该如何更改我的ID,因为它们不是整数呢?
case GET_LIST: {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
// above, the field param is always set as 'id'. How can I change it
const query = {
sort: JSON.stringify([field, order]),
range: JSON.stringify([
(page - 1) * perPage,
page * perPage - 1,
]),
filter: JSON.stringify(params.filter),
};
options.headers.set('scopes','admin:read');
const bearerToken = localStorage.getItem('userToken');
url = `${apiUrl}/${resource}?${stringify(query)}`;
break;
}
答案 0 :(得分:1)
可以在列表中配置排序字段: https://marmelab.com/react-admin/List.html#default-sort-field
<List sort={{ field: 'id', order: 'ASC' }} {...props}>