Black Lives Matter. Please consider donating to Black Girls Code today.

How to get last row index in DataTable?

Hi, I faced some issues and need help to solve it
I want my table to look like this

but i still got no clue how to make the column can has diff color and get the last row index on datatable(I cannot set a number cause it will always change depend on the db).
I also wanna style my table just like the example (to set column height), but by far my table looked like this

and this is how my datatable code look like

                style_cell={'textAlign': 'left'},
                        'textAlign': 'center',
                        'backgroundColor': colors['kotak1'],
                        'fontWeight': 'bold',
                        'maxWidth': '180px'
                style_table={'overflowX': 'scroll'},
                    "if": {"row_index": 'last row'},
                    "backgroundColor": "#a8d7ff"}]


Hi, long time since you asked the question but I was looking for an answer and managed to cobble together something myself.

In my code I am generating the data of the dataTable on the fly (as it appears you are doing) and mine is contained within a callback. Within that callback (originally only used for the ‘data’) I passed the following extra output:

Output(component_id=‘tableName’, component_property=‘style_data_conditional’)

Then as part of the data generation you take a check of the length of the df/list of dicts used for the ‘data’ component:
rowNumber = int(len(tableDataListOfDicts)-1)

then create the formatting argument:
tableFormatting = [{‘if’: {‘row_index’: rowNumber}, ‘backgroundColor’: ‘rgb(whatever)’}]

hope that helps!