Material-table: how to add a new row with my own customised Add Button

Created on 3 Apr 2019  路  2Comments  路  Source: mbrn/material-table

Hi @mbrn

Can you please share a code snippet which describes how to trigger the same functionality that the default add Icon button is doing i.e to create a new row, with my customised action button placed at the left of the toolbar.

<button> Add New Task </button>

help wanted

Most helpful comment

I was able to mimic the default add button's functionality with the following:

<>
  <MaterialTable innerRef={ref => this.myTable = ref} />
  <MyCustomButton 
    onClick={() => this.myTable.setState({ showAddRow: !this.newMenuMealsRef.state.showAddRow })}
  >
    Add New Item
  <MyCustomButton>
</>

All 2 comments

I was able to mimic the default add button's functionality with the following:

<>
  <MaterialTable innerRef={ref => this.myTable = ref} />
  <MyCustomButton 
    onClick={() => this.myTable.setState({ showAddRow: !this.newMenuMealsRef.state.showAddRow })}
  >
    Add New Item
  <MyCustomButton>
</>

It works like a charm :) thanks a lot @jbkuczma @mbrn

Was this page helpful?
0 / 5 - 0 ratings