How to Select First row index of P-dataTable in Angular ?

1,795 views
Skip to first unread message

har...@rapidd.net

unread,
Jun 29, 2017, 5:22:24 AM6/29/17
to Angular and AngularJS discussion

I am showing some data in P-dataTable but i want to put input text field on click on first row of table only (I am getting inout box but get repeated through out of thee table).

Sander Elias

unread,
Jul 1, 2017, 6:01:27 AM7/1/17
to Angular and AngularJS discussion
Hi Harsh,

Can you build a plunk to show us what it is you are after? 

Regards
Sander

Zlatko Đurić

unread,
Jul 1, 2017, 5:15:57 PM7/1/17
to Angular and AngularJS discussion
On Thursday, June 29, 2017 at 11:22:24 AM UTC+2, har...@rapidd.net wrote:

I am showing some data in P-dataTable but i want to put input text field on click on first row of table only (I am getting inout box but get repeated through out of thee table).


This should be really easy to achieve - give your column template the rowIndex and show the imput if the rowIndex === 0 - like this:  https://plnkr.co/edit/yETk9NqbhQkcAfoaAVpA?p=preview

Here's the relevant bit:
<p-column field="Col1" header="Column 1" [sortable]="true" [style]="{'width': '200px'}">
    <template let-data="rowData" let-ri="rowIndex" pTemplate="body">
      <span *ngIf="ri !== 0">{{ data['Col1'] }}</span> <input type="text" *ngIf="ri === 0">
    </template>
  </p-column>

The important part is that let-ri="rowIndex" where you give your template the rowIndex.

Disclaimer though, I don'tuse PrimeNG but I was curious so went and looked it up.
Reply all
Reply to author
Forward
0 new messages