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

Warn if id in rows is missing #342

Closed
arheinjohnson opened this issue Sep 22, 2020 · 12 comments · Fixed by #349
Closed

Warn if id in rows is missing #342

arheinjohnson opened this issue Sep 22, 2020 · 12 comments · Fixed by #349
Labels
component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation

Comments

@arheinjohnson
Copy link

I'm simply trying to use the onRowClick param and it doesn't seem to work, and when I look through the source code, it's not clear that this has been implemented?

<DataGrid
rows={rows}
columns={columns}
autoHeight
sortModel={sortModel}
pageSize={20}
onRowClick={() => console.log("Hello, World!")}
// disableSelectionOnClick={true}
/>

@arheinjohnson
Copy link
Author

Fyi, the issue was that my ColDef did not include an 'id' field, nor did my rows. Once including those, onRowClick now works.

@mbrookes mbrookes added component: data grid This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 23, 2020
@oliviertassinari oliviertassinari removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 23, 2020
@oliviertassinari oliviertassinari changed the title onRowClick doesn't seem to be implemented or does not work? id requirement? Sep 23, 2020
@oliviertassinari
Copy link
Member

@arheinjohnson How did you figure the origin of the issue?

I think that there is an opportunity to improve the DX here. I think that we should either warn if the row id is missing or remove this requirement with a fallback on the index of the row. The latter won't work when performing server-side sorting or filtering.

@dtassone What do you think about keeping the ID as a requirement but console.error when a row doesn't have it?

Regarding the column, this sounds like a bug. I don't see any practical reason for forcing the definition of a column for the ID. We can open a new issue for this one. @dtassone do you confirm?

@dtassone
Copy link
Member

The ID column is used internally to optimize rendering and performance. ATM if it is not provided, it creates issues.
I think we can fix it internally by providing a fallback id in case the user does not pass an id column

@oliviertassinari oliviertassinari changed the title id requirement? Warn if id in rows is missing Sep 24, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 24, 2020

Regarding the column id, it seems to work without https://codesandbox.io/s/red-sun-49nyg?file=/demo.tsx. So I have opened #346 to simplify the docs where possible.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 24, 2020

ID column

@dtassone Are we talking about the same thing? I'm making a reference to the entry in the columns array prop. Are you talking about the id the grid build for each column? I assume right now, it uses the field value to build its internal column id?

@oliviertassinari
Copy link
Member

I have renamed the issue to focus on this problem: https://codesandbox.io/s/romantic-kilby-wl9cc?file=/demo.tsx. If you don't provide rows with an id. It fails everywhere and you have no tips around what's going wrong:

Capture d’écran 2020-09-24 à 11 06 05

I think that we developers should expect a first error message with how the id property on each row is required.

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Sep 24, 2020
@arheinjohnson
Copy link
Author

I wouldn't say I found the origin of the issue but while reading through the docs found the reference to a rows id. Agreed you don't need an id column for this to work and I really only needed an id in the rows. Would definitely be helpful to get that in a message if id isn't entered by the developer into the rows.

@scollins33
Copy link

The ID column is used internally to optimize rendering and performance. ATM if it is not provided, it creates issues.
I think we can fix it internally by providing a fallback id in case the user does not pass an id column

@dtassone - sorry in advance if this is a time waster (I promise I looked through the docs twice).

My dataset does have a unique id property but it is not called "id". I don't want to map through and just add one as that is taxing. Am I misunderstanding what you're talking about or is there a prop I can pass to target a specific "unique id property"?

@dtassone
Copy link
Member

@scollins33 ATM there is no property to let you map id with another field.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 29, 2020

I don't want to map through and just add one as that is taxing.

@scollins33 What do you mean by "taxing"? From a developer experience or runtime perspective?

@scollins33
Copy link

@dtassone - Ok, thanks for the clarity. Would that be a potential feature request? I can write up an Issue if you guys want me to.

@oliviertassinari - runtime perspective. I'm working with our backend team to see if we can get our columns renamed in a more consistent way (just call it "id"!!) so I can avoid having a loop anywhere.

Thanks for the time guys :) really appreciate the work yall do

@dtassone
Copy link
Member

@scollins33 yes it is a potential feature request, please feel free to open an issue. We will pick it up as soon as we can.
It shouldn't be a big one ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants