如何向ngTable添加行

德州697

我正在尝试将预输入选择中的数据添加到ngTable中的行。为此,我使用了常规的引导表,但是添加行之后,我需要能够编辑数据。INgTable有一个可以执行此操作的表,因此我想进行切换。我对ngTable不熟悉,所以任何帮助都将非常有用。朋克

   //Add New POD Row
$scope.data = [];
$scope.addRow = function () {
    $scope.data.push({
        'JobItemName': $scope.masterItem.MLItemCode,
        'JobItemDescription': $scope.masterItem.JobItemDescription,
    });
    $scope.masterItem.JobItemName = '';
    $scope.masterItem.JobItemDescription = '';
};
//Remove POD Row
$scope.removeRow = function (JobItemName) {
    var index = -1;
    var comArr = eval($scope.data);
    for (var i = 0; i < comArr.length; i++) {
        if (comArr[i].JobItemName === JobItemName) {
            index = i;
            break;
        }
    }
    if (index === -1) {
        alert("Something gone wrong");
    }
    $scope.data.splice(index, 1);
};

   $scope.tableParams = new ngTableParams({
            page: 1,            // show first page
            count: 10           // count per page
        }, {
            total: $scope.data.length, // length of data
            getData: function($defer, params) {
                $defer.resolve($scope.data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
            }
        });
大卫·费尔南德斯

为什么要使用ngTable指令而不是这样的东西:

<table class="table table-striped table-hover">
        <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="row in table" ng-click="editMyRow(row)">
            <td ng-bind="row.column1"></td>
            <td ng-bind="row.column2"></td>
        </tr>
        </tbody>
    </table>

在这种情况下,每次编辑这些值时,表都会实时更改。

控制器将类似于:

angular.module('test').controller('blah', $scope){

 $scope.table = {};
 $scope.table.row = [];
 $scope.table.row.add({
      column1: '',
      column2: ''
 });

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章