添加新行并定位该行的分页



我正在制作一个动态表。我有一个工作添加按钮,它向表中添加行,我还有一个工作分页。现在我习惯把这两者结合起来。

当我添加新行时,我习惯于放在创建行的分页的最后一页。现在,我总是停留在分页的第一页,然后手动转到最后一页。

有人能帮忙吗?提前感谢!

script.js

(function () {
    "use strict";
var table = angular.module('myTable', ['angularUtils.directives.dirPagination','ngStorage']); 

table.controller('TodoCtrl', function ($scope, $localStorage) {
    $scope.$storage = $localStorage.$default({
        "todos":[
            { "id":1,"text":"drive a car"},
            { "id":2,"text":"go to work"}
        ]           
    });
    $scope.todoData = $localStorage.todos;  
});

$scope.addRow = function (arr) {
            console.log(arr);
            arr.push({'id':$scope.id, 'text': $scope.text});        
            };
});

index.html

<button type="button" class="btn btn-default btn-block" ng-click="addRow($storage.todos)">New record</button>
<table>
    <thead></thead>
        <tbody>
            <tr dir-paginate="todo in todoData">
                <td>
                    {{ todo.id }}
                </td>
                <td>                
                    {{ todo.text }}
               </td>
           </tr>
     </tbody>
</table>
<dir-pagination-controls
    max-size="5"
    direction-links="true"
    boundary-links="true" >
</dir-pagination-controls>

编辑:

current-page="myCurrentPage"添加到包含dir-paginate的标记中,在您的示例中为<tr>标记。将$scope.myCurrentPage = Math.ceil($scope.todos.length/$scope.entryLimit);添加到addDeveloperRow函数中。

工作Plunker

最新更新