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

Conditional detail panel options

Open jakeleventhal opened this issue 7 years ago • 28 comments

Is your feature request related to a problem? Please describe. I want to be able to do the same thing as here https://github.com/mbrn/material-table/issues/609 as you are able to do for actions with detail panels.

Describe the solution you'd like I want to conditionally have a detail panel for a row based on the conditions of the row

jakeleventhal avatar Jun 05 '19 01:06 jakeleventhal

Didn't realize there was already a prop for this

jakeleventhal avatar Jun 05 '19 01:06 jakeleventhal

There is a way to disabled the panel, but not hide it completely - reopening

jakeleventhal avatar Jun 05 '19 01:06 jakeleventhal

I can add hidden field to detailPanel asap.

mbrn avatar Jun 05 '19 11:06 mbrn

Is there a way to conditionally not have a detail panel - something like :

                      {
                      render: rowData => {
                         if (!rowData.headerRow) {
                            return <h2>yes</h2> 
                         } else {
                            return false
// this would completely remove any detail panel for this row
                         }
                      }
                      }
                    ]}```

raph90 avatar Aug 08 '19 15:08 raph90

@raph90 I think it makes more sense to have a separate function that returns true or false that is different from the render function

so you would have something like:

// Show panel function
detailsPanelVisibile: (rowData) => rowData.someProp === 'sample',
// Render panel function
detailsPanel: (rowData) => <h2>rowData.data</h2>

jakeleventhal avatar Aug 08 '19 20:08 jakeleventhal

I do have the same issue. It would be nice to have the same component for tables in both the cases - when I have to display the row details, and when I don't have any row details to show.

My suggestion is to make detailsPanel prop to accept false as well in case there is no component to render.
like: detailsPanel: { rowHasDetails ? rowData => ... : false }

annuranjan2019 avatar Aug 09 '19 15:08 annuranjan2019

Another way to do it would be to simply add another property:

detailPanel: [
  rowData => ({
    visible: rowData.expandable,
    render: () => <div>{rowData.name} {rowData.surname}</div>,
  })
]

cox-michael avatar Aug 20 '19 21:08 cox-michael

Has anyone figured out a way to do this? If so can you please share?

Otherwise, is anyone working on a pull request??

aesnyder avatar Aug 21 '19 14:08 aesnyder

The workaround is to disable it and use display: none on your icon:

const detailPanel = [
  rowData => ({
    disabled: !rowData.expandable,
    icon: () => <UnfoldMore className={!rowData.expandable && classes.displayNone} />,
    openIcon: UnfoldLess,
    render: () => <div>content</div>,
  })
];

cox-michael avatar Aug 21 '19 15:08 cox-michael

Thanks @ldsmike88

aesnyder avatar Aug 21 '19 15:08 aesnyder

The workaround is to disable it and use display: none on your icon:

const detailPanel = [
  rowData => ({
    disabled: !rowData.expandable,
    icon: () => <UnfoldMore className={!rowData.expandable && classes.displayNone} />,
    openIcon: UnfoldLess,
    render: () => <div>content</div>,
  })
];

THANK YOU SO MUCH!!!!!!!

michaelgthomas avatar Mar 23 '20 18:03 michaelgthomas

There is still a column where the icon should be. Is there a way not to show that column for detailPanel?

cristiangabor avatar Jun 25 '20 05:06 cristiangabor

Up topic :) !

My suggestion is to make detailsPanel prop to accept false as well in case there is no component to render. like: detailsPanel: { rowHasDetails ? rowData => ... : false }

This would be nice solution!

viktor-mir avatar Aug 03 '20 17:08 viktor-mir

The workaround is to disable it and use display: none on your icon:

const detailPanel = [
  rowData => ({
    disabled: !rowData.expandable,
    icon: () => <UnfoldMore className={!rowData.expandable && classes.displayNone} />,
    openIcon: UnfoldLess,
    render: () => <div>content</div>,
  })
];

BIG BIG THANK YOU! For a while it is best solution among existed.

viktor-mir avatar Aug 03 '20 17:08 viktor-mir

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 Dec 10 '20 20:12 stale[bot]

not stale

jakeleventhal avatar Dec 10 '20 21:12 jakeleventhal

const detailPanel = condition ? [] : [
  rowData => ({
    render: () => <div>content</div>,
  })
];

With this decision, we don't render element.

petr-like avatar Dec 13 '20 19:12 petr-like

@petr-like I have a field code95, if this field empty - I don't want to show panel option for a particular row. My code is: detailPanel={ rowData => (rowData.code95==='') ? [] : [ rowData => ({ render: () => <div>content</div>, }) ] } Unfortunately, it doesn't work. Can you please suggest the right way?

AlekseiMordas avatar Dec 17 '20 10:12 AlekseiMordas

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 Mar 17 '21 10:03 stale[bot]

not stale

jakeleventhal avatar Mar 17 '21 11:03 jakeleventhal