Material-table: DetailPanel icons

Created on 17 Jun 2019  路  6Comments  路  Source: mbrn/material-table

Hello,
I try to set custom icon and openIcon for detailPanel. Can you show me expample icon type React.ReactElement?

help wanted wontfix

Most helpful comment

I made it work with icon: () => <Icon color="primary">list</Icon> panel property and by parsing the detailPanel array to any (as a temporary solution)

All 6 comments

Here are same examples.
https://material-table.com/#/docs/features/detail-panel.

There are only cases when icon is string. I want to do something such as:
detailPanel={ [ {
icon; \ ....
} ] }
But first variant show error in CustomIcon: "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of CustomIcon."
And second variant show typescript error : "ts(2322) The expected type comes from property 'detailPanel' which is declared here on type 'IntrinsicAttributes & MaterialTableProps & { className?: string | undefined; } & { children?: ReactNode; }''

In m-table-body-row.js

if (typeof panel === "function") {
                panel = panel(this.props.data);
              }

              const isOpen = (this.props.data.tableData.showDetailPanel || '').toString() === panel.render.toString();

              let iconButton = <this.props.icons.DetailPanel />;
              let animation = true;
              if (isOpen) {
                if (panel.openIcon) {
                  iconButton = <CustomIcon icon={panel.openIcon} />;
                  animation = false;
                }
                else if (panel.icon) {
                  iconButton = <CustomIcon icon={panel.icon} />;
                }
              }
              else if (panel.icon) {
                iconButton = <CustomIcon icon={panel.icon} />;
                animation = false;
              }

              iconButton = (
                <IconButton
                  size={this.getElementSize()}
                  key={"key-detail-panel-" + index}
                  style={{ transition: 'all ease 200ms', ...this.rotateIconStyle(animation && isOpen) }}
                  disabled={panel.disabled}
                  onClick={(event) => {
                    this.props.onToggleDetailPanel(this.props.path, panel.render);
                    event.stopPropagation();
                  }}
                >
                  {iconButton}
                </IconButton>);

              if (panel.tooltip) {
                iconButton = <Tooltip key={"key-detail-panel-" + index} title={panel.tooltip}>{iconButton}</Tooltip>;
              }

First the field iconProps of detailPanel described in the document seems not handled.

Second, it could be nice to accept a type component also for the openIcon and icon.

What do you think?
I'm also looking to custom the content of iconbutton, to display a counter with the icon.

I made it work with icon: () => <Icon color="primary">list</Icon> panel property and by parsing the detailPanel array to any (as a temporary solution)

You can achieve this by using a function like @sebastiendan mentioned.
Here's an example I use for hiding the detail column an parent objects when using tree data.

const detailColumn = [
    rowData => ({
      disabled: !rowData.parentID,
      icon: () => rowData.parentID ? <SomeIcon/> : <></>,
      openIcon: () => <SomeOpenIcon/>,
      render: rowData => <div>Nice details</div>,
      tooltip: rowData.parentID ? 'Cool Tooltip' : null,
    }),
  ]

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slevy85 picture slevy85  路  3Comments

jlgreene2 picture jlgreene2  路  3Comments

victorwvieira picture victorwvieira  路  3Comments

Mihier-Roy picture Mihier-Roy  路  3Comments

ModPhoenix picture ModPhoenix  路  3Comments