更改React Jhipster的默认排序和顺序

问题描述 投票:1回答:1

我正在使用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以按publishedDatedesc顺序初始化排序?

reactjs jhipster
1个回答
0
投票
我根据useState object set中的问题使它起作用了>

const[paginationState, setPaginationState] = useState({activePage: 1, itemsPerPage: ITEMS_PER_PAGE, sort: 'publishedDate', order: 'desc'});

© www.soinside.com 2019 - 2024. All rights reserved.