7

我是 ng-grid 的新手。我正在学习带有编辑模板选项的 ng-grid。我已经创建了带有编辑复选框选项的网格。但我不知道编辑复选框后如何在该网格中获取值?谢谢你。

这里 JSfiddle

var myapp = angular.module('myapp', ["ui", "ngGrid"]);

myapp.controller('myctrl', function($scope, $http) {

    $scope.testInfo= "TestInfo";

  $scope.data = {
    persons: [],
    selected:[],
    load: function () {
      $http.get("/echo/json/").success(function(data) {
      $scope.data.persons = [
          {id:1, name:"Max", number:51323.512,value:'on'},
            {id:2, name:"Adam", number:7245.2,value:'on'},
            {id:3, name:"Betty", number:828,value:'off'},
            {id:4, name:"Sara", number:23452.45182,value:'on'}
          ];

        $scope.data.selected[0] = $scope.data.persons[0];

      });
    }
  };

   var cellTemplate = "<div ng-class=\"'ngCellText colt' + $index\">"
                    + " <span ng-cell-text>{{COL_FIELD}}</span>"
                    + "</div>";
    var cellEditTemplate = '<input type="checkbox" ng-checked="row.entity.value==\'on\'" ng-input="COL_FIELD" /></div>';

  $scope.grid = {
    options: {
      data: "data.persons",
      selectedItems: $scope.data.selected,
      multiSelect: false,
      columnDefs: [
        {field:"id", displayName:"ID"},
        {field:"name", displayName:"Name"},
        {field:"number", displayName:"Nummer", cellFilter:"number:2"},
          {field: "value",displayName:"Value",enableCellEdit : true,cellTemplate : cellTemplate,
          editableCellTemplate : cellEditTemplate}

        ]
    }
  };



});

<div ng-app="myapp">
    <div ng-controller="myctrl">

      <a class="btn" ng-click="data.load()">Get data!</a>
      <div ng-grid="grid.options" class="grid"></div>
      <ul ng-repeat="item in data.selected">
        <li>{{item}}</li>
      </ul>
    </div>
</div>
4

1 回答 1

12

您现在可能已经想通了,但一种可能的选择是在复选框选择器中使用 ng-grids 构建。它没有在其主页上的示例中显示,但在 API 中列为一个选项。

showSelectionCheckbox: true
于 2013-08-08T15:54:04.623 回答