How to add row numbers in DataTable ?

UI Components for React
Post Reply
jjayaraman
Posts: 16
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

aragorn
Posts: 3761
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: 16
Joined: 09 Jul 2013, 10:49

12 Sep 2019, 16:20

Thanks it works :-)

aragorn
Posts: 3761
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?

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests