如何使用angularjs智能表中的复选框处理每一行选择?

时间:2014-05-20 09:36:39

标签: angularjs smart-table

如何使用每行的复选框在智能表中选择行...并在每个循环后显示所选行的计数?它必须使用angularjs和smart-table

[来源] http://lorenzofox3.github.io/smart-table-website/

1 个答案:

答案 0 :(得分:2)

您可以使用cellTemplateUrl包含一个复选框(请参阅智能表文档)

在select.html

 <input type="checkbox" ng-click="$parent.$parent.$parent.$parent.noSelected(select)" ng-model="select" />

在Html中

<!DOCTYPE html>
<html ng-app="myApp">

  <head>
    <script data-require="angular.js@1.0.7" data-semver="1.0.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="smart.js"></script>
    <script src="app.js"></script>
    <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
  </head>

  <body ng-controller="mainCtrl" ng-init="noRow=0">
    <h1>{{greetings}} Plunker!</h1>

    No of row selected {{noRow}}

    <smart-table config="globalConfig" columns="columnsConfig" rows="items"></smart-table>
  </body>

</html>

在app.js

var app=angular.module('myApp',['smartTable.table']);

app.controller('mainCtrl',['$scope',function(scope){
  scope.greetings='hello';

   scope.noRow=0;

  scope.noSelected=function(select){

   if(select){

   scope.noRow=scope.noRow+1;
   }else{

     scope.noRow=scope.noRow-1;
   }

  }
scope.items=[
    {name:'mahesh',lastName:'kumar'},
    {name:'sachin',lastName:'ramesh'},
    {name:'varun',lastName:'gupta'},
    {name:'vijay',lastName:'kumar'},
    {name:'prem',lastName:'raj'},
    {name:'gandhi',lastName:'gandhi'},
    {name:'sathish',lastName:'kumar'},
    {name:'ram',lastName:'prasad'},
    {name:'siva',lastName:'guru'},
    {name:'dilli',lastName:'ganesh'}
    ];

  scope.globalConfig={
    isPaginationEnabled:false,
    selectionMode:'single'
  };

  scope.columnsConfig=[
      {label:'actions',cellTemplateUrl:'select.html'},
    {label:'name',map:'name'},
    {label:'last Name',map:'lastName'}

    ];

}])

请查看plunker演示。

希望这能解决您的问题:)