我正在使用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
顺序初始化排序?
const[paginationState, setPaginationState] = useState({activePage: 1, itemsPerPage: ITEMS_PER_PAGE, sort: 'publishedDate', order: 'desc'});