Simone
Simone

Reputation: 163

Can I stop people editing specific cells in ag-Grid?

I want to make only some cells in a Column editable. I can see how I make a whole column readonly but not just some cells. We are using ag-Grid 24 React Version together with AdapTable.

Upvotes: 3

Views: 1416

Answers (2)

Shuheb
Shuheb

Reputation: 2352

The Column Definition property editable can take either a boolean or callback function. If you provide a callback, you can add a condition to allow cells within a column to be editable.

For example, if we wanted to allow a cell to be editable only if it contained the string 'Michael':

  const isAthleteEditable = (params) => {
    const value = params.data[params.column.getColId()];
    if (value.includes('Michael')) {
      return true;
    } else {
      return false;
    }
  };

See this implemented in the following sample.

Upvotes: 4

Jonny Wolfson
Jonny Wolfson

Reputation: 121

You can do this by in ag-Grid and in AdapTable.

The AdapTable way is to provide an implementation of isCellEditable in Edit Options (which you can then style through either the readOnlyCellStyle or editableCellStyle properties in User Interface Options if required).

See this demo for more info.

Upvotes: 0

Related Questions