无法通过分页获取ng-repeat对象的过滤计数

时间:2016-07-19 16:03:22

标签: angularjs pagination angularjs-ng-repeat

我想对ng-repeat对象的过滤结果实现分页。由于语法规则别名只能应用于结尾,因此我无法获得转发器对象的正确计数。

<md-card class="blur-box">
    <md-input-container>
        <label>Search</label>
        <input ng-change="updated()" type="text" ng-model="search" md-maxlength="10">
    </md-input-container>
    <md-table-container>
        <table md-table md-row-select multiple ng-model="selected">
            <thead md-head md-order="query.order">
                <!-- <tr>{{query.order}}</tr> -->
                <tr md-row>
                    <th md-column md-numeric md-order-by="key">Roll Number</th>
                    <th md-column md-order-by="value.firstName">firstName</th>
                    <th md-column md-order-by="value.lastName">lastName</th>
                    <th md-column md-order-by="value.email">email</th>
                    <th md-column md-order-by="value.dob">dob</th>
                    <th md-column md-order-by="value.college">college</th>
                    <th md-column md-order-by="value.course">course</th>
                    <th md-column md-order-by="value.status">status</th>
                    <th md-column md-order-by="value.note">note</th>
                </tr>
            </thead>
            <tbody md-body>
                <tr md-row md-select="student" md-select-id="key" ng-repeat="student in students | filter: search | orderBy: query.order | limitTo: query.limit : (query.page -1) * query.limit as fStudents"> 
                    <td md-cell>{{student.key}}</td>
                    <td md-cell>{{student.value.firstName}}</td>
                    <td md-cell>{{student.value.lastName}}</td>
                    <td md-cell>{{student.value.email}}</td>
                    <td md-cell>{{student.value.dob}}</td>
                    <td md-cell>{{student.value.college}}</td>
                    <td md-cell>{{student.value.course}}</td>
                    <td md-cell>{{student.value.status}}</td>
                    <td md-cell>{{student.value.note}}</td>
                </tr>
            </tbody>
        </table>
    </md-table-container>
    <md-table-pagination md-limit="query.limit" md-limit-options="limitOptions" md-page="query.page" md-total="{{fStudents.length}}" md-page-select="true" md-on-paginate="logPagination"></md-table-pagination>
</md-card>

例如,在上面的代码中,我最初约有27个对象。但由于分页,Count({{fStudents.length}})总是说5,除非object.length小于5。

需要帮助来解决这个问题。

1 个答案:

答案 0 :(得分:0)

您需要使用filterResult。将ng-repeat更改为:

ng-repeat="student in (filterResult = (students | filter: search | orderBy: query.order | limitTo: query.limit : (query.page -1) * query.limit as fStudents))"

然后将md-total更改为:

md-total="{{search ? filterResult.length : fStudents.length}}"