react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

When will the add a row and delete a row functionality be implemented

Open jbp17 opened this issue 6 years ago • 14 comments

I really like your grid. It looks nice and easy to use and customize. Nice job! But it is missing the functionalities of adding and deleting a row and I can't use it unless these functionality is available. What is your timeline for getting it implemented?

jbp17 avatar Sep 13 '18 21:09 jbp17

hello @jbp17 currently, after the react-bootstrap-table2-tookkit supported, I think we will have add/delete row soon. But I can not tell you the timing due to sometime I am busy. but I will implement it ASAP. thank 👍

AllenFang avatar Sep 16 '18 08:09 AllenFang

Thank you!

jbp17 avatar Sep 17 '18 12:09 jbp17

@jbp17 We implemented them ourselves in the grid, using column formatter to conditionally display an edit field, etc. Works nicely.

waynebrantley avatar Dec 01 '18 16:12 waynebrantley

@waynebrantley can you show how you added a delete and add button to add/delete rows?

alyssa1995 avatar Feb 06 '19 17:02 alyssa1995

Here is an example delete button. This is the column definition for the delete column.

        {
            dataField: "databasePkey",
            text: "Remove",
            formatter: (cellContent: string, row: IMyColumnDefinition) => {
                if (row.canRemove)
                    return <button className="btn btn-danger btn-xs" onClick={() => this.handleDelete(row.databasePkey)}>Delete</button>
                return null
            },
        },

The handler for handleDelete does an api call to backend to delete row...that call is a promise and after it completes it makes an api call to backend to get new grid data. It of course could have just removed it directly from the grid state or whatever.

waynebrantley avatar Feb 09 '19 14:02 waynebrantley

what is string and IMyColumnDefinition and row.databasePkey here. { dataField: "databasePkey", text: "Remove", formatter: (cellContent: string, row: IMyColumnDefinition) => { if (row.canRemove) return <button className="btn btn-danger btn-xs" onClick={() => this.handleDelete(row.databasePkey)}>Delete return null }, },

prateek04 avatar Apr 03 '19 21:04 prateek04

@waynebrantley Thank you for sharing your solution. What I actually mean to say is when will the functionality of updating the entire row be added. Right now, the user can click or double-click any cell and modify the content of it. It is a very nice and convenient feature. But it might cause accidentally change of the data very easily. Some end-user might not like that. They might prefer to an update button at the beginning or end of the row. When clicking on the button, the row changes to an update state. The user can update any cell in the same row. When he/she is satisfied with the change, it will click the Save button. The row will return to a state that is not editable.

jbp17 avatar May 16 '19 21:05 jbp17

I was so excited to use this library then ran into the same issue: if it can't edit a row at once and insert and delete then it has become useless to me. I agree with @waynebrantley .

thanateros avatar Jul 18 '19 14:07 thanateros

@jbp17 Yes, we do the same thing - we have an edit button on the row, and we create a form outside the grid....which is great because rarely is it 'simple' enough to edit in the grid directly..

waynebrantley avatar Jul 18 '19 15:07 waynebrantley

@waynebrantley I think your advice just saved my day.

thanateros avatar Jul 18 '19 19:07 thanateros

@waynebrantley and @AllenFang I have a problem when deleting the last element in a page. The paginator breaks down because is not taking into account the change, this page should dissapear due to lacks of elements in it, but instead it throws an error: image Please could you help me?

dailymp avatar Sep 06 '19 06:09 dailymp

Credits to @waynebrantley . I simplified it for others who need it in Javascript and more verbose example. The example assumes, that your objects have a property called id that identifies the object.

const dealColumns = [
  {
    dataField: "firstname",
    text: "First Name",
  },
// all your columns and data
  {
    dataField: "id",
    text: "Remove",
    editable: false,
    formatter: (cellContent, row) => {
      return (
        <button
          className="btn btn-danger btn-xs"
          onClick={() => handleDelete(row.id)}
        >
          Delete
        </button>
      );
    },
  },
];

const handleDelete = (rowId) => {
  console.log(rowId);
};

maakle avatar May 05 '20 22:05 maakle

I'm just getting started with using this package. Adding and deleting rows is definitely something I need. Has this been officially implemented?

peterkronenberg avatar Nov 24 '21 02:11 peterkronenberg

@peterkronenberg you can refer @mathiasklenk for deleting rows.

Fashad-Ahmed avatar Jan 15 '22 20:01 Fashad-Ahmed