【发布时间】:2020-03-10 15:04:21
【问题描述】:
我正在使用 Jhipster 6.8.0 并尝试根据以下代码更改默认排序(排序方式:publishedDate 和 order:desc):
const [paginationState, setPaginationState] = useState(getSortState(props.location, ITEMS_PER_PAGE));
const getAllEntities = () => {
if (search) {
props.getSearchEntities(
search,
paginationState.activePage - 1,
paginationState.itemsPerPage,
`${paginationState.sort},${paginationState.order}`
);
} else {
// setPaginationState({
// ...paginationState,
// order: 'desc',
// sort: 'publishedDate'
// });
props.getEntities(paginationState.activePage - 1, paginationState.itemsPerPage, `publishedDate,desc`);
}
};
添加了相关接口
export interface IPaginationBaseState {
itemsPerPage: number;
sort: string;
order: string;
activePage: number;
}
export declare const getSortState: (location: any, itemsPerPage: any) => IPaginationBaseState;
评论部分是我当前如何更改默认排序,但我认为这不是最好的方法,因为页面加载了 2 次。
如何更改useState 以按publishedDate 和desc 顺序初始化排序?
【问题讨论】: