新入门的角度和智能表..
此智能表设置可以正确工作和过滤,但尝试重置或清除过滤器不会重新过滤表。为什么不行?
使用ng-model绑定更新输入不会触发智能表正在寻找的手表吗?
Plunker可在此处获得:http://plnkr.co/edit/4os3oWeJtEtMfa89QoQd?p=preview
代码:
var actionQueue = [
{ Type: 'User Access Request', Description: 'test test test test test test test', DateRequested: '5/5/15' },
{ Type: 'User Access Request', Description: 'blah blah', DateRequested: '3/3/10' },
{ Type: 'Project Approval Request', Description: 'project needs approving', DateRequested: '1/1/08' }
];
$scope.actionQueueCollection = actionQueue;
$scope.predicates = [{ Name: 'All', Value: '' }, { Name: 'User Access Request', Value: 'User Access Request' }, { Name: 'Project Approval Request', Value: 'Project Approval Request' }];
$scope.selectedPredicate = $scope.predicates[0];
$scope.clearFilter = function () {
$scope.selectedPredicate = $scope.predicates[0];
$scope.searchFilter = '';
}
标记:
<table st-table="actionQueueCollection" >
<thead>
<tr>
<th>
<div>
<label class="col-sm-1 control-label" for="filterType">Filter: </label>
<div class="col-sm-8">
<select class="form-control input-sm" id="filterType" name="filterType" ng-model="selectedPredicate" ng-options="predicate.Name for predicate in predicates track by predicate.Value" st-search="Type"></select>
</div>
</div>
</th>
<th colspan="3">
<div class="form-horizontal form-group-sm">
<div class="input-group col-sm-12">
<input st-search placeholder="search" class="form-control input-sm" type="search" ng-model="searchFilter" />
<button type="button" class="btn-sm btn-default" ng-click="clearFilter()">CLEAR</button>
</div>
</div>
</th>
</tr>
<tr>
<th>Type</th>
<th>Description</th>
<th>Date Requested</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="action in actionQueueCollection">
<td>{{action.Type}}</td>
<td>{{action.Description}}</td>
<td>{{action.DateRequested}}</td>
</tr>
</tbody>
</table>
发布于 2016-02-21 02:08:29
几乎是一样的事情。这样用起来会简单一点。
.directive("stResetSearch", function() {
return {
restrict: 'EA',
require: '^stTable',
link: function(scope, element, attrs, ctrl) {
return element.bind('click', function() {
return scope.$apply(function() {
var tableState;
tableState = ctrl.tableState();
tableState.search.predicateObject = {};
tableState.pagination.start = 0;
return ctrl.pipe();
});
});
}
};
})然后用法是这样的
<button type="button" st-reset-search>Clear Filters</button>发布于 2015-03-24 07:44:50
这就是我想出来的.我不确定这是不是一种好的方法,但从我收集的信息来看,我需要创建许多指令来在智能表格上发挥功能?
<button type="button" class="btn-sm btn-default" smart-table-reset="clearFilter()">
.directive('smartTableReset', ['$parse', function ($parse) {
return {
restrict: 'A',
require: '^stTable',
link: function (scope, element, attr, ctrl) {
var tableCtrl = ctrl;
var fn = $parse(attr['smartTableReset']);
element.on('click', function (event) {
ctrl.tableState().search = {};
tableCtrl.search('', '');
scope.$apply(function () {
fn(scope, {
$event: event
})
});
});
}
};
https://stackoverflow.com/questions/29221692
复制相似问题