如何使用每行的复选框在智能表中选择行...并在每个循环后显示所选行的计数?它必须使用angularjs和smart-table
答案 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演示。
希望这能解决您的问题:)