Mui-datatables: Display row number

Created on 29 Jun 2020  路  2Comments  路  Source: gregnb/mui-datatables

Is there a way to display the row numbers? One of my tables is ranking assets and it would be very helpful for the users to see if an asset is ranked, for example, 28 or 12. Thanks!

Most helpful comment

Thanks. For future searches here's the code I used. I added a column as the first one:

    {
        name: '',
        label: '',
        options: {filter: false,
            customBodyRender : (value, tableMeta, update) => {
                let rowIndex = Number(tableMeta.rowIndex) + 1;
                return ( <span>{rowIndex}</span> )
            }
        },
    },

All 2 comments

See the customBodyRender/customBodyRenderLite methods. customBodyRender has a rowIndex on the tableMeta object and customBodyRenderLite takes in a rowIndex parameter. You can use this value for the display.

Thanks. For future searches here's the code I used. I added a column as the first one:

    {
        name: '',
        label: '',
        options: {filter: false,
            customBodyRender : (value, tableMeta, update) => {
                let rowIndex = Number(tableMeta.rowIndex) + 1;
                return ( <span>{rowIndex}</span> )
            }
        },
    },
Was this page helpful?
0 / 5 - 0 ratings