M
M
MarEeeeeee2021-06-30 11:13:06
React
MarEeeeeee, 2021-06-30 11:13:06

How to add an additional column to the table if the data comes as an object?

I am using the material ui component

<DataGrid className={styles.table} columns={columns} rows={rows} getRowId={row => row.tradePlace_id} />


I pull the data into rows from the server, the task is to add a static column to the incoming data, that is, the data for it does not come from the server.
In addition, the column should be a button, when clicked, it will be possible to capture the entire row to which it belongs.
I initialize like this
const rows: GridRowsProp = tradePlaces.tradePlaces;

  const columns: GridColDef[] = [
        {field: 'col1', headerName: 'Изменить', width: 500}, // Здесь должна быть кнопка
        {field: 'tradePlace_id', headerName: '№', width: 300},
        {field: 'name', headerName: 'Название', width: 300},
        {field: 'adress', headerName: 'Адрес', width: 300},
    ];


Tell me how to implement this, I looked at the documentation for the component, but did not quite understand how to solve the task. I use TS in my project, I will be extremely grateful if there is an example with it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-06-30
@0xD34F

looked at the documentation for the component, but...

looked bad

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question