2

I am using react table 7.0 , How can i add and iconColumn , and on click of that , need to show an dropdown.

 {
        Header: "",
        accessor: "actionColumn",
        disableSortBy: true,
        Cell: ({ original }) => (
           
            <div className="cursor__pointer ">
                <Icon className="padding5" iconName="RemoveLink" aria-hidden="true" />
            </div>
        )
    },

I am able to render an icon on the column like above. How can i render a dropdown on click of it ?

bharath
  • 111
  • 1
  • 2
  • 15
  • Are you using some components library? If no - then you can check them - a lot of them have dropdown components, like here: https://react-bootstrap.github.io/components/dropdowns/ If you don't want to include whole library for that, then you can also add single component like this one: https://github.com/fraserxu/react-dropdown – mehowthe Feb 22 '21 at 12:58
  • But , how do i tell react-table to render a dropdown on click of that icon ? not able to figure that out.. – bharath Feb 23 '21 at 09:19
  • I've attached example below – mehowthe Feb 24 '21 at 12:02

1 Answers1

3

Here's an example, how to do this with this simple @trendmicro-frontend/react-dropdown library:

      {
        Header: "",
        accessor: "actionColumn",
        disableSortBy: true,
        Cell: ({ original }) => (

            <div className="cursor__pointer ">
              <Dropdown
                  onSelect={(eventKey) => {
                  }}
              >
                <Dropdown.Toggle btnStyle="link" noCaret
                >
                  <Icon className="padding5" iconName="RemoveLink" aria-hidden="true" />
                </Dropdown.Toggle>
                <Dropdown.Menu>
                  <MenuItem header>Header</MenuItem>
                  <MenuItem eventKey={1}>link</MenuItem>
                  <MenuItem divider />
                  <MenuItem header>Header</MenuItem>
                  <MenuItem eventKey={2}>link</MenuItem>
                </Dropdown.Menu>
              </Dropdown>
            </div>
        )
      },

A working example here:

https://codesandbox.io/s/distracted-leftpad-c6onr?file=/src/App.js

mehowthe
  • 761
  • 6
  • 14