# AG Grid Cell Editing with using string values

**URL:** <https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [December 21, 2023, 4:11pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090 "2023-12-21T16:11:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![seventy77](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@seventy77](https://community.plotly.com/u/seventy77)\
**Post date:** [December 21, 2023, 4:11pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/1 "2023-12-21T16:11:08Z")

</div>

Hi, I was looking at this documentation:

> **[Cell Editing | Dash for Python Documentation | Plotly](https://dash.plotly.com/dash-ag-grid/cell-editing)**
>
> Overview of cell editing in Dash AG Grid

In the following example, they show how to make a specific column cell editable if it matches the condition:

“editable”: {“function”: “params.data.year == 2012”},

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/d/b/dbbbf60ccfca491b40f0804ca6606897caefa17d.png)

I’m trying to do something similar but I struggled. What I am trying to do is to make the age column editable only if the value column Athlete contains the word ‘e’. Any Ideas on how to achieve this?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [December 21, 2023, 4:18pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/2 "2023-12-21T16:18:46Z")

</div>

Hello @seventy77,

I think this might work:

```auto
{"field": "age", "editable": {"function": "params.data ? params.data.athlete.contains('e') : null"}}

```

If not `contains` try `includes`.

---

<div class="post-metadata">

**Author:** ![seventy77](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@seventy77](https://community.plotly.com/u/seventy77)\
**Post date:** [December 21, 2023, 4:37pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/3 "2023-12-21T16:37:16Z")

</div>

Hi @jinnyzor,

Unfortunately this is not working for me :(,

I do this analogy using the example above. But my code looks like this:

```auto

    {
        'field': 'Morning',
        'cellStyle': {
            # Set of rules
            "styleConditions": [
            {
                    "condition": "params.value.includes('Hot')",
                    "style": {"backgroundColor": "pink", "borderRadius": "15px", "borderWidth": "1px", "borderColor": "black","paddingRight": "5px","boxShadow": "3px 3px 2px gray"},
                },
                {
                    "condition": "params.value.includes('Cold')",
                    "style": {"backgroundColor": "skyblue", "borderRadius": "15px", "borderWidth": "1px", "borderColor": "black","paddingRight": "5px","boxShadow": "3px 3px 2px gray"},
                },
            ],
            # Default style if no rules apply
            "defaultStyle": {"backgroundColor": "white"},
            "editable": {"function": "params.data ? params.data.Morning.includes('f') : null"}

        }

```

Is the same problem basically, and what is it instead of using ‘f’ I want to be able to evaluate this against a Python variable called keyword. This would be my second problem

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [December 21, 2023, 4:51pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/4 "2023-12-21T16:51:51Z")

</div>

This works for me:

```auto
import dash_ag_grid as dag
from dash import Dash, html, dcc
import pandas as pd

app = Dash( __name__ )

df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)

app.layout = html.Div(
    [
        dcc.Markdown("This grid has editing enabled on all columns"),
        dag.AgGrid(
            id="basic-editing-example",
            columnDefs=[{"field": i, 'editable': {"function": "params.data ? params.data.athlete.includes('e') : null"}
                         if i == 'age' else True} for i in df.columns],
            rowData=df.to_dict("records"),
            columnSize="sizeToFit",
            defaultColDef={"editable": True},
        ),
    ],
    style={"margin": 20},
)

if __name__ == " __main__":
    app.run(debug=True, port=8000)

```

---

<div class="post-metadata">

**Author:** ![seventy77](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@seventy77](https://community.plotly.com/u/seventy77)\
**Post date:** [December 21, 2023, 5:11pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/5 "2023-12-21T17:11:08Z")

</div>

@jinnyzor,

Great now it works for me :), final question how can I restrict the edit option only to the age column? And can I also store the ‘e’ word on a Python variable and then evaluate it?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [December 21, 2023, 5:12pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/6 "2023-12-21T17:12:25Z")

</div>

What do you mean exactly?

Right now, the only one that is conditional is `age`, all the others are `True`, if you want all others to be off then change the `True` to `False`.

---

<div class="post-metadata">

**Author:** ![seventy77](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@seventy77](https://community.plotly.com/u/seventy77)\
**Post date:** [December 21, 2023, 5:19pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/7 "2023-12-21T17:19:59Z")

</div>

Thanks, I understood! 🙂 just changed into False.

the other question is, that I want to be able to store the keyword into a variable because this might change depending on each user so how can I save this keyword into a variable and then evaluate it?

{“function”: “params.data ? params.data.athlete.includes( **keyword** ) : null”}

I also want to make them editable if keyword is presented or if the cell have null values.  
keyword |cell\_null

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [December 21, 2023, 5:31pm UTC](https://community.plotly.com/t/ag-grid-cell-editing-with-using-string-values/81090/8 "2023-12-21T17:31:48Z")

</div>

I would actually use a dcc.Store so you dont have to keep updating it.

```auto
"function": "params.data ? params.data.athlete.includes(localStorage.getItem('variable')) : null"

```

Then if your layout pass a `dcc.Store(id='variable', storage_type='local', data='')`, then have a clientside\_callback that updates that value:

```auto
app.clientside_callback(
"""function (n, id) {
    if (n) {
         localStorage.setItem('variable', n)
         dash_ag_grid.getApi(id).refreshCells()
         return n
    } 
    return window.dash_clientside.no_update
}""",
Output('variable','data'), Input('trig', 'prop'), Input('grid', 'id')
)

```

^ the trigger should be something like an input box or something that has a value to make it easier to update 🙂
