如何在角表中添加一个选择模型复选框

时间:2015-12-05 06:27:02

标签: angularjs datatable selectionmodel

带有输入类型复选框的角度表创建代码。

angular.module("tableApp",[]).controller('tableAppCtrl', ['$scope',
  function($scope) {
    $scope.titleString="Table Demo";
    $scope.prodDataTable = [{
      "productType": "A",
      "productName": "Aaaaaa"
    }, {
      "productType": "B",
      "productName": "Bbbbbb"
    }, {
      "productType": "C",
      "productName": "Cccccc"
    }];
  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div  ng-app="tableApp" ng-controller="tableAppCtrl">
  <h3>{{titleString}}</h3>
<table>
  <tr>
    <th><input type="button" value="checkALL"></th>
    <th>Product Type</th>
 <th>Product Name</th>

  </tr>

  <tr ng-repeat="d in prodDataTable">
    <td><input type="checkbox"></td>
    <td>{{d.productType}}</td> 
    <td>{{d.productName}}</td>
  </tr>


</table>
  </div>

我一直在使用角度表,我必须在其中包含一个选择模型。

请建议使用表格的方式或链接。

2 个答案:

答案 0 :(得分:1)

使用此功能,但您需要处理重复值创建 -

contents

<div  ng-app="tableApp" ng-controller="tableAppCtrl">
<h3>{{titleString}}</h3>
<table>
  <tr>
    <th><input type="button" value="{{(selectAllval==true) ? 'UncheckALL' : 'checkALL'}}" ng-click="selectAll(selectAllval)"></th>
    <th>Product Type</th>
 <th>Product Name</th>

  </tr>

  <tr ng-repeat="d in prodDataTable">
    <td><input type="checkbox" ng-checked="selectAllval" ng-click="setProductType(d.productType)"></td>
    <td>{{d.productType}}</td> 
    <td>{{d.productName}}</td>
  </tr>


</table>

{{setProductTypes}}

答案 1 :(得分:0)

尝试以下代码 -

&#13;
&#13;
angular.module("tableApp",[]).controller('tableAppCtrl', ['$scope',
 function($scope) {
  $scope.titleString="Table Demo";
  $scope.selectAllval= false;
  $scope.selectAll= function(val){
	if(val==false){
		$scope.selectAllval= true;
	} else{
		$scope.selectAllval= false;
	}
  };
  $scope.prodDataTable = [{
  "productType": "A",
  "productName": "Aaaaaa"
  }, {
  "productType": "B",
  "productName": "Bbbbbb"
  }, {
  "productType": "C",
  "productName": "Cccccc"
  }];
 }
]);
&#13;
  

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <div  ng-app="tableApp" ng-controller="tableAppCtrl">
  <h3>{{titleString}}</h3>
	<table>
	  <tr>
	    <th><input type="button" value="{{(selectAllval==true) ? 'UncheckALL' : 'checkALL'}}" ng-click="selectAll(selectAllval)"></th>
	    <th>Product Type</th>
	 <th>Product Name</th>

	  </tr>

	  <tr ng-repeat="d in prodDataTable">
	    <td><input type="checkbox" ng-checked="selectAllval" ></td>
	    <td>{{d.productType}}</td> 
	    <td>{{d.productName}}</td>
	  </tr>


	</table>
  </div>
&#13;
&#13;
&#13;