0

I want to add a button to material-table toolbar. it doesnt do anything relevant to the table. it just opens a modal with some information

I want to add a button called "quotations" to the left side of the "add item" button.

enter image description here

Sandbox code: https://codesandbox.io/embed/charming-yalow-4pnk4?fontsize=14&hidenavigation=1&theme=dark

2
  • 2
    Please provide the code or a codesandbox Commented Nov 5, 2021 at 13:21
  • @v1s10n_4 Here is the sandbox code codesandbox.io/embed/… Commented Nov 5, 2021 at 13:50

3 Answers 3

4

As Will Evers mentioned, it's possible to add whatever is necessary to Toolbar of the MaterialTable component by using Toolbar prop :

          Toolbar: (props) => (
            <div
              style={{
                display: "flex",
                justifyContent: "flex-end",
                alignItems: "center"
              }}
            >
              <Button
                style={{ height: "fit-content" }}
                color="primary"
                variant="contained"
              >
                Quotations
              </Button>
              <div style={{ width: "13rem" }}>
                <MTableToolbar {...props} />
              </div>
            </div>
          ),

Working Demo

Sign up to request clarification or add additional context in comments.

Comments

2

Per the docs, it looks like you need to override the Toolbar component of your table and you should be able to add what ever you want above the column headers:

https://material-table.com/#/docs/features/component-overriding

https://i.sstatic.net/J0mqf.png

2 Comments

i don't want to add anything to the column headers. I want to add another button next to "add item" button. I can override toolbar and add another button like in github.com/mbrn/material-table/issues/2048 using divs. I want to know whether there is a different way to do it.
you wouldnt be, you would be editing the component that sits above the columns
-1

Use this prop in the component tag

renderTopToolbarCustomActions={() => (
    <Button
        variant="contained"
        color="primary"
        size="large"
        onClick={() => console.log('something')}
    >
        Quotations
    </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.