Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Overriding add row function in material table

I want to execute a function before the add row editable opens. enter image description here Before this UI opens up I want to execute a function. (like console.log('Hello')) This is my current material table code.

            <MaterialTable
                title="Timesheet"
                columns={columns}
                data={DataArray}
                icons={tableIcons}
                editable={{
                onRowAddCancelled: rowData => console.log('Row adding cancelled'),
                onRowUpdateCancelled: rowData => console.log('Row editing cancelled'),
                onRowAdd: newData =>
                    new Promise((resolve, reject) => {
                        
                        setTimeout(() => {
                            // add row
                        }, 1000);
                    }),    

                }}
                options={{
                    actionsColumnIndex: -1,
                    addRowPosition: "first",
                    search:false,
                    exportButton: true,
                    
                }}
                
            />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can put the code you want to execute in the onRowAdd callback function, for example

    <MaterialTable
      title="Timesheet"
      columns={columns}
      data={DataArray}
      icons={tableIcons}
      editable={{
        onRowAddCancelled: rowData => console.log('Row adding cancelled'),
        onRowUpdateCancelled: rowData => console.log('Row editing cancelled'),
        onRowAdd: newData => {
            console.log('Hello');
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    // add row
                }, 1000);
            });  
        }
      }}
      options={{
        actionsColumnIndex: -1,
        addRowPosition: "first",
        search:false,
        exportButton: true,
      }}
    />
  );

If you want to call your function on the + button click, you need to add the actions. For example

    <MaterialTable      
      actions={[
        {
          icon: 'add',
          tooltip: 'Add User',
          isFreeAction: true,
          onClick: (event) => alert("You want to add a new row")
        }
      ]}
    />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!