Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass rowIndex to column template #268

Closed
cagataycivici opened this issue Apr 27, 2016 · 1 comment
Closed

Pass rowIndex to column template #268

cagataycivici opened this issue Apr 27, 2016 · 1 comment
Assignees
Labels
Type: New Feature Issue contains a new feature or new component request
Milestone

Comments

@cagataycivici
Copy link
Member

Expose rowIndex as a template variable in addition to existing column and rowdata;

<p-column field="color" header="Color">
            <template #col #car="rowData" #ri="rowIndex">
                {{ri}}
                <span [style.color]="car[col.field]">{{car[col.field]}}</span>
            </template>
        </p-column>
@cagataycivici cagataycivici added the Type: New Feature Issue contains a new feature or new component request label Apr 27, 2016
@cagataycivici cagataycivici added this to the 1.0.0-beta.4 milestone Apr 27, 2016
@cagataycivici cagataycivici self-assigned this Apr 27, 2016
@ilianiv
Copy link

ilianiv commented Aug 12, 2016

I've noticed that rowIndex is actually an absolute row index:

((page_number - 1) * items_per_page + row_number)

It's nice but if I use lazy loaded datatable rowIndex can't help me a lot because it doesn't match item's index in component's collection.

Example:
I'm lazy loading events in datatable with 5 items limit and I want to be able to remove an event from events array by index.

  • On first datatable page there is no problem with rowIndex. We can delete some event with events.splice(rowIndex, 1) for example.
events: [ {event a}, {event b}, {event c}, {event d}, {event e} ];

Clicking on 2nd row's delete button will remove events[1] element - Great!
image

  • But on page two events array gets filled with other 5 events (lazy loaded from an API) indexed from 0 to 4 again
events: [ {event f}, {event g}, {event h}, {event i}, {event j} ];

Clicking on 2nd row's delete button will remove events[6] element - but no! There is no event at position 6 😢
image

So I suggest renaming rowIndex to absRowIndex and adding relRowIndex variable that will return relative row index for current datatable page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature Issue contains a new feature or new component request
Projects
None yet
Development

No branches or pull requests

2 participants