Dash AG-Grid: Column order

Hi,

Are there any ways to change column order without using callback ? I am now using column group function but my column order is shown as wrong way. I would like to show Metrics first and then Name and then BMP. but somehow bmp is position in front of Name.

def getcolDef(df):
    df_columnDefs = []
    for i in df.columns:
        if i == 'METRICS':
            df_columnDefs.append({
            "headerName":'METRICS/CATEGORY',
            "minWidth": 250,
            "pinned":"left",
            "lockPinned": True,
            "showRowGroup": i,
            "cellRenderer": 'agGroupCellRenderer',
            "cellRendererParams": {
                "suppressCount": True},
            })
            df_columnDefs.append({"headerName": "METRICS/CATEGORY", "field": i, "rowGroup": True, "hide": True,"lockPinned": True,"rowGroupIndex":1})
        elif i == 'NAME':
            df_columnDefs.append({
            "headerName":'NAME',
            "minWidth": 300,
            "pinned":"left",
            "lockPinned": True,
            "showRowGroup": i,
            "cellRenderer": 'agGroupCellRenderer',
            "valueGetter": '(params) => {if (params.data) {return params.data.i;}}',
            "cellRendererParams": {
                "suppressCount": True},
            })
            df_columnDefs.append({"headerName": "", "field": i, "rowGroup": True, "hide": True,"lockPinned": True, "rowGroupIndex":2})
        elif i == 'AGENCY':
            df_columnDefs.append({"headerName": "BMP", "field": i, "minWidth": 250, "pinned":True,})
        else:
            df_columnDefs.append({"headerName": i, "field": i, "type": 'rightAligned',"valueFormatter": {"function": "Numberformat(params[spoiler]This text will be blurred[/spoiler].value)"}})
   
    return df_columnDefs

Hello @hwang,

The way to make the columns show in the order that you want to is to arrange the columnDefs in that order.

Alternatively, you can save a columnState of how you want the columns to be shown and save that to load with your grid.

Hi @jinnyzor

Thanks for reply. I thought I have already arranged the column in the right order I would like to show (in the code I copied). However when I run app, the order changed somehow. is that because I used the if -statement when define column def?

Id print your column order after the function.

However your df is arranged should be the way it is showing.