Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ag-grid: Disable cells based on content in other cells on the same row

I'm looking for help about a feature I will implement using ag-grid. Here is a plunker.

I have a table with X items and 3 columns. In the the first column, I have some readonly text and in the second and third columns I have custom cellEditor (on click a dropdown menu is displayed).

Target: I want the cells in the third column to be disabled by default (on click, the dropdown is not displayed) and the dropdown is displayed (in a cell in the third column) only if the cell on the second column on the same row has value (an item is selected from the dropdown).

enter code here (must have code in order to put plunker links :/)

Example: On row one: column 1 has value (by default) and the user select an item from the dropdown on column 2. Then and only then he is able to select an item from the dropdown in the third column. The user is not able to select an item from the third column on other rows since their column two is empty.

like image 679
Marin Takanov Avatar asked Jan 02 '23 16:01

Marin Takanov


1 Answers

You can handle editable mode dynamically

headerName: 'C',
field: 'c',
cellEditor: 'searchEditor',
editable: (params:IsColumnFuncParams)=>{ return params.data.b },
cellEditorParams: {
    values: this.c
}

Set to true if this col is editable, otherwise false. Can also be a function to have different rows editable.

editable?: boolean | IsColumnFunc;

ag-grid-community\src\ts\entities\colDef.ts

export interface IsColumnFuncParams {
    node: RowNode;
    data: any;
    column: Column;
    colDef: ColDef;
    context: any;
    api: GridApi;
    columnApi: ColumnApi;
}

Update: singleClickEdit

Set to true to enable Single Click Editing for cells, to start editing with a single click. See Single Click Editing. Default: false

like image 94
un.spike Avatar answered May 08 '23 02:05

un.spike