1

I have an angular html snippet below of a table I am trying to wire up using Dir-Paginate and also have the table row change class based on a function on the controller.js

<tr dir-pagination="response in vm.responses  | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage" class="{{ vm.getRowClass($index) }}">
    <td> {{ $index + 1 }}</td>
    <td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
    <td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
 <tr>

<dir-pagination-controls ng-show="appvm.showDataTable()" boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="ng/pagination"></dir-pagination-controls>

If i remove all of the Dir-Pagination syntax and make it just a normal ng-repeat the vm.getRowClass($index) works as it should, changing the class based on the function's logic. However, when I try to add the dir-pagination syntax in, i am given a $Index is undefined error.

Problem seems to be that Dir-Paginate does not allow me to pass in an $index or any item on the same line as the <tr>

1
  • 1
    Do you mean dir-paginate instead of dir-pagination? Also try ng-class instead of just class. I am passing $index into an ng-click function and it's taking just fine. Commented Jul 7, 2015 at 20:07

1 Answer 1

1

After the comment and some playing around i found the solution.

I needed to add track by $index to the end of the itemsPerPage: $root.pagination.itemsPerPage area.

Shown correctly below.

<tr dir-pagination="response in vm.responses  | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage track by $index" class="{{ vm.getRowClass($index) }}">
    <td> {{ $index + 1 }}</td>
    <td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
    <td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
 <tr>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.