0

I use in my React app:

import MUIDataTable from "mui-datatables";

I'd like to add some button to my last column header (instead of the column name):

 <MUIDataTable
            data={data}
            columns={columns}
            options={options}
        >
        </MUIDataTable>

where columns:

export const columns = [
    {
        name: "name",
        label: "Nazwa",
        options: {
            filter: true,
            sort: true,
        }
    },
    {
        name: "productNumber",
        label: "Numer",
        options: {
            filter: true,
            sort: true,
        }
    }, (...)

How to do that? Is it possible? I can't find anything

2 Answers 2

1

You can define a custom body for column. You can add a column like this:

{
  name: "Age",
  options: {
     filter: false,
     customBodyRender: (value, tableMeta, updateValue) => (
        <FormControlLabel
          control={<TextField value={value || ''} type='number' />}
          onChange={event => updateValue(event.target.value)}
        />
     )
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

one more question - is it possible to add button only to the last column HEADER but the remaining rows in that column should contain data from data variable (like in other rows in other columns)
Ok I have solution for my problem - I have to use customHeadRender instead :)
0

You need to use customHeadRender

const columns = [
    {
        name: "id",
        label: "Id",
        options: {
            filter: false,
        }
    },
    {
        name: "subject",
        label: "Subject",
        options: {
            filter: true,
            sort: false,
        }
    },
    {
        name: "button",
        options: {
            customHeadRender: ({index, ...column}) => {
                return (
                    <Button key={index}>
                        Click
                    </Button>
                )
            }
        }
    }
];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.