【问题标题】:Change Default Sort and Order for React Jhipster更改 React Jhipster 的默认排序和顺序
【发布时间】: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 以按publishedDatedesc 顺序初始化排序?

【问题讨论】:

    标签: reactjs jhipster


    【解决方案1】:

    我根据useState object set 中的问题和答案让它工作

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-20
      • 1970-01-01
      • 2011-04-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多