Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Query Documentation - Wrong example - SetSort & SetPerPage errors #6108

Closed
newfylox opened this issue Mar 31, 2021 · 2 comments · Fixed by #6115
Closed

Custom Query Documentation - Wrong example - SetSort & SetPerPage errors #6108

newfylox opened this issue Mar 31, 2021 · 2 comments · Fixed by #6115
Assignees

Comments

@newfylox
Copy link

newfylox commented Mar 31, 2021

Following this example Rendering <Datagrid> With A Custom Query will throw 2 errors if using sorting and pagination features.

  • setSort must be present inside <ListContextProvider value={{setSort: ...}} />
  • setPerPage must be present inside <Pagination setPerPage={...} />

It could be something like this:

const [perPage, setPerPage] = React.useState(25); // update here instead of const perPage = 50;
const [sort, setSort] = React.useState({ field: "myfield", order: "DESC" });

...

<ListContextProvider
    value={{
      basePath: "/expenses",
      data: keyBy(data, "id"),
      ids: data.map(({ id }) => id),
      currentSort: sort,
      selectedIds: [],
      setSort: (field, order) => { // update here
        setSort({ field, order });
      },
    }}
  >

...

<Pagination page={page} perPage={perPage} setPage={setPage}
  setPerPage={setPerPage} // update here
  total={total} />
@djhi
Copy link
Collaborator

djhi commented Apr 1, 2021

Thanks for reporting. Can you open a PR ?

@fzaninotto
Copy link
Member

Sorry, I pushed the fix to master by mistake. Reopening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants