Page 1 of 1

How to add row numbers in DataTable ?

Posted: 11 Sep 2019, 12:08
by jjayaraman
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

Re: How to add row numbers in DataTable ?

Posted: 11 Sep 2019, 14:12
by mert.sincan
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}/>
            ...

Re: How to add row numbers in DataTable ?

Posted: 12 Sep 2019, 16:20
by jjayaraman
Thanks it works :-)

Re: How to add row numbers in DataTable ?

Posted: 13 Sep 2019, 09:03
by mert.sincan
Glad to hear, thanks a lot for the update!

Best Regards,

Re: How to add row numbers in DataTable ?

Posted: 14 Oct 2019, 03:06
by kelwy
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?

Re: How to add row numbers in DataTable ?

Posted: 20 Apr 2021, 13:24
by nirav.vikani
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>
        );
    }
    

Re: How to add row numbers in DataTable ?

Posted: 07 May 2021, 00:26
by mert.sincan
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,