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

Rendering a Datagrid outside of a resource #5020

Closed
oliverox opened this issue Jul 8, 2020 · 2 comments
Closed

Rendering a Datagrid outside of a resource #5020

oliverox opened this issue Jul 8, 2020 · 2 comments

Comments

@oliverox
Copy link

oliverox commented Jul 8, 2020

react-admin version 3.7.0

Hi!
I used to be able to render a Datagrid not attached to a specific resource. I used to pass the Datagrid an array of items via the data prop and their respective ids via the ids prop. How to achieve this now in version 3.7.0?
Based on the following lines, it seems RA is now only reading the ListContext for data and ids. I am unable to find a way to pass my data and ids props to my Datagrid now. Thank you for your help.

const {
basePath,
currentSort,
data,
ids,
loaded,
onSelect,
onToggleItem,
resource,
selectedIds,
setSort,
total,
} = useListContext(props);

@fzaninotto
Copy link
Member

Hi,

You must now enclose your Datagrid inside a ListContext.Provider. See the jsdoc of that component for details.

@megantaylor
Copy link
Contributor

i just ran into this issue when i tried to upgrade from 3.3.0. its no longer clear from docs how to do datagrids with custom data. what ended up working was:

<ListContext.Provider
// @ts-ignore (we will remove this at some point and pass in the rest of the data that is required)
      value={{
        data,
        currentSort,
        ids
      }}
    >
<DataGrid  /> // dont need to pass additional `data`, `ids` or `currentSort` props
    </ListContext.Provider>

based on the documentation we initially tried using useListController but that requires the data to be stored a certain way in redux and for my use case was not the right answer. hope this helps someone else.

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

No branches or pull requests

3 participants