如何使用每一行的复选框来选择智能表中的行..并在每个周期后显示选定行的计数?它必须使用 angularjs 和 smart-table
问问题
6126 次
1 回答
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演示。
希望这能解决你的问题:)
于 2014-07-21T18:02:35.927 回答