How to add row numbers in DataTable ?

UI Components for React
Post Reply
jjayaraman
Posts: 17
Joined: 09 Jul 2013, 10:49

11 Sep 2019, 12:08

How to add row numbers in DataTable ?

I tried

Code: Select all

let-i="rowIndex" 
but not working

Code: Select all

                    <DataTable value={rows} paginator={true} rows={20} rowsPerPageOptions={[5, 10, 20, 50]} autoLayout={true} header={header} footer={footer} let-i="rowIndex">
                        <Column field="i" header="#" />
                        <Column field="paramCode" header="Code" sortable={true} />
                        <Column field="paramDesc" header="Description" sortable={true} />
                        <Column field="paramValue" header="Value" sortable={true} />
                        <Column header="Edit / Delete" body={this.actionTemplate} style={{ textAlign: 'center', width: '8em' }} />
                    </DataTable>

Thanks

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

11 Sep 2019, 14:12

Please try;

Code: Select all

    this.onIndexTemplate = this.onIndexTemplate.bind(this);
    ...
    onIndexTemplate(data, props) {
        return props.rowIndex;
    }
    
    ...
    <DataTable value={this.state.cars} ...>
            <Column field="Index" header="" body={this.onIndexTemplate}/>
            ...

jjayaraman
Posts: 17
Joined: 09 Jul 2013, 10:49

12 Sep 2019, 16:20

Thanks it works :-)

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

13 Sep 2019, 09:03

Glad to hear, thanks a lot for the update!

Best Regards,

kelwy
Posts: 1
Joined: 11 Oct 2019, 16:20

14 Oct 2019, 03:06

aragorn wrote:
11 Sep 2019, 14:12
Please try;

Code: Select all

    this.onIndexTemplate = this.onIndexTemplate.bind(this);
    ...
    onIndexTemplate(data, props) {
        return props.rowIndex;
    }
    
    ...
    <DataTable value={this.state.cars} ...>
            <Column field="Index" header="" body={this.onIndexTemplate}/>
            ...
How do i use this method with dynamic columns?

nirav.vikani
Posts: 2
Joined: 23 Dec 2020, 08:16

20 Apr 2021, 13:24

Hello,

I want to print row index in data table. Earlier it was working fine but new release of primereact its not working. I am using primreact 6.1.0. any solutions?

Code: Select all

 
 rowIndexTemplate = (rowData, props) => {
        let index = parseInt(props.rowIndex + 1);
        return (
            <React.Fragment>
                <span>{index}</span>
            </React.Fragment>
        );
    }
    

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

07 May 2021, 00:26

Hello,

@nirav.vikani, I couldn't replicate it. Please try; https://codesandbox.io/s/reverent-tree- ... sicDemo.js

@kelwy please try; https://codesandbox.io/s/optimistic-jol ... micDemo.js

Best Regards,

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests