I am using Jhipster 6.8.0 and trying to change default sorting (sort by : publishedDate and order : desc) based on the following code:
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`);
}
};
Added the relevant interface
export interface IPaginationBaseState {
itemsPerPage: number;
sort: string;
order: string;
activePage: number;
}
export declare const getSortState: (location: any, itemsPerPage: any) => IPaginationBaseState;
The commented part is how I currently change the default sorting, however I dont think thats the best approach because the page loads 2 times.
How can I change the useState to initialize the sorting by publishedDate and desc order ?