material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Export to csv displays [object object] for complex data column

Open dashName opened this issue 6 years ago • 15 comments

When I am trying to export to csv it works fine for simple data but for array of objects it does not export correctly.while i am displaying correctly in table.

dashName avatar Apr 08 '20 18:04 dashName

Could anyone assist with this one? I have the same problem, data object have subobjects, not flat structure

am0nshi avatar Apr 14 '20 08:04 am0nshi

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Jul 13 '20 09:07 stale[bot]

Can you share the object and how you display it?

Domino987 avatar Jul 13 '20 12:07 Domino987

Well, we experience the very same case with an array of objects. The following field is being passed to the Material-Table:

[{
  active: true,
  name: 'foobar'
}, {
  active: false,
  name: 'test'
}]

The render enables us to loop / iterate over the entries and define how the content will be rendered. Is there any way, to do the very same for the plain text (export) content? I'd think of it as a callback function, that is being triggered by the export feature, which enables the column to define it's own export logic.

{
  title: t('users.roles'),
  field: 'roles',
  render: rowData => (
    <>
      {_.map(rowData.roles, role => {
        return <span className={(rowData.active) ? classes.roleLabel : classes.disabledRoleLabel}>{role.name}</span>
      })}
    </>
  ),
  // this would be the optional callback function
  // it passes the rowData and enables the user to specify custom behaviours
  // in this case, we would convert the value to a comma-separated list
  export: rowData => {
    return rowData.roles.map(role => role.name).join(',')
  }
}

beevelop avatar Jul 14 '20 10:07 beevelop

I think that would be a great addition. Can you create a PR to address this?

Domino987 avatar Jul 14 '20 20:07 Domino987

This is very much needed here too, we are able to render and customFilterAndSearch but sadly unable to export.

hbermani avatar Aug 06 '20 15:08 hbermani

Same here, would be a great feature.

boehm-e avatar Aug 31 '20 13:08 boehm-e

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Nov 29 '20 14:11 stale[bot]

It's unfortunate to see this issue is being marked as stale, any progress guys?

hbermani avatar Nov 30 '20 10:11 hbermani

And also, if my columns have any jsx elements like { field: "name", title: <b>{"Name"}</b>, width: 370, }

this one when I export I get column header as [object Object] any callback or anyother API which I can make to export as plain text ?

jagadeeshkoka avatar Jan 24 '21 04:01 jagadeeshkoka

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Apr 24 '21 05:04 stale[bot]

having the same error.

ghost avatar Nov 23 '21 00:11 ghost

This project was abandoned by the owner . Please move to material-table-core for the community fork.

Domino987 avatar Nov 23 '21 01:11 Domino987

This project was abandoned by the owner . Please move to material-table-core for the community fork.

abandoned?

ghost avatar Nov 25 '21 21:11 ghost

same error

tranquockhanhdev avatar Jul 17 '24 12:07 tranquockhanhdev