tleunen / react-mdl

React Components for Material Design Lite
https://tleunen.github.io/react-mdl/
MIT License
1.76k stars 255 forks source link

[DataTable] accept nested objects in "rows" array #498

Open sillybutt0 opened 6 years ago

sillybutt0 commented 6 years ago

Currently we need to connect data in "rows" prop of DataTable component with TableHeader's "name" prop to work properly. But having nested object in "rows" array will not connect them and sort.

Example of how now works:

const data = [{email: 'test@test.com', name: 'Alex'}];

<DataTable rows={data}>
  <TableHeader name="email">Email</TableHeader>
  <TableHeader name="name">Name</TableHeader>
</DataTable>

And how does not work:

const data = [{email: 'test@test.com', profile: { name: 'Alex' }}];

<DataTable rows={data}>
  <TableHeader name="email">Email</TableHeader>
  <TableHeader name="name">Name</TableHeader>
</DataTable>

I suggest to type object keys like "profile.name" and make if work correctly with further sorting.

vegansk commented 6 years ago

You can use workaround:

<TableHeader name="profile" cellFormatter={(profile) => profile.name}>Name</TableHeader>