gregnb / mui-datatables

Datatables for React using Material-UI
MIT License
2.71k stars 932 forks source link

Return original data entry in customRowRender #1614

Open kristijorgji opened 3 years ago

kristijorgji commented 3 years ago

Expected Behavior

The callback of customRowRender is returning for the first argument one array instead of the original data entry which is key based object

This can be fine, but we need also to get back the original data object key based instead of being converted to array.

That means that if I pass to


const COLUMNS = [
 {
        name: 'name',
        label: 'Name',
    },
    {
        name: 'surname',
        label: 'Surname',
    },
];

const data = [
  {
  name: 'kristi',
  surname: 'jorgji',
  }
];

return
 <MUIDataTable
                title={'Users'}
                columns={COLUMNS}
                data={data}
</>

I expect to be able to get the data object entry exactly with key structure somehow in the customRowRender instead of being in array format like below currently (I am simplifying here, but in real usage is complex data structure nested etc and such option is really needed, getting back in array format is not helpful.

[
 0 => kristi
 1 => jorgji
]

Current Behavior

customRowRender: (data) => { console.log(data); // the data here will be array, cannot find any way to get back the original data structure }

Your Environment

"@material-ui/core": "^4.11.1", "mui-datatables": "^3.7.3", "@types/mui-datatables": "^3.7.0", "react": "^17.0.1",

wdh2100 commented 3 years ago

@kristijorgji

Hello

using enableNestedDataAccess

example : https://github.com/gregnb/mui-datatables/blob/master/examples/data-as-objects/index.js

Name Type Default Description
enableNestedDataAccess string "" If provided a non-empty string (ex: "."), it will use that value in the column's names to access nested data. For example, given a enableNestedDataAccess value of "." and a column name of "phone.cell", the column would use the value found in phone:{cell:"555-5555"}. Any amount of nesting will work. Example demonstrates the functionality.
kristijorgji commented 3 years ago

@kristijorgji

Hello

using enableNestedDataAccess

example : https://github.com/gregnb/mui-datatables/blob/master/examples/data-as-objects/index.js

Name Type Default Description enableNestedDataAccess string "" If provided a non-empty string (ex: "."), it will use that value in the column's names to access nested data. For example, given a enableNestedDataAccess value of "." and a column name of "phone.cell", the column would use the value found in phone:{cell:"555-5555"}. Any amount of nesting will work. Example demonstrates the functionality.

Hi, I am already using that but that still gives me array in the customRowRender callback as first argument, and not my original data object.

That is not the issue I am mentioning, that is working totally as expected I have one object photo: {url: string} and can access it in colument definition proplery with photo.url and so on all is fine. Issue is that I cannot get my object in the customRowRenderer beause there the data has lost its original format now is array as explained in my xample

wdh2100 commented 3 years ago
customRowRender function   Override default row rendering with custom function. customRowRender(data, dataIndex, rowIndex) => React Component

using dataIndex