我有data-ng-grid
我希望使用<select>
(下拉列表)过滤特定列,但我似乎无法使其正常工作。我是AngularJS的新手,所以我可能完全错了,但我的代码示例在
HTML:
<div data-ng-controller="manualrecunreconciled as vm" class="form-horizontal">
<div class="form-group">
<div class="col-sm-6">
<select name="manualrecfilter" ng-options="choice for choice in manualrecfilter" ng-model="sourceNameSelected" ng-change="filterOptions.filterText = sourceNameSelected.type" class="form-control" style="width:100% !important">
<option>All</option>
</select>
</div>
<div class="col-sm-6 pull-right">
<div class="input-group">
<input class="form-control pull-right" type="text" name="SearchBox" data-ng-model="searchfilter" placeholder="Search for ..." />
<span class="input-group-addon">
<i class="fa fa-search" style="color: #555"></i>
</span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="gridStyle" data-ng-grid="gridOptions" id="recoptions" style="height: 325px;"></div>
</div>
</div>
控制器:
$scope.manualrecfilter = [
'All',
'P - Property',
'I - Investment',
'B - Both'
];
$scope.sourceNameSelected = '';
$scope.filterOptions = {
filterText: "",
};
function updategridoptions() {
$scope.gridOptions = {
data: 'myData',
rowHeight: 40,
enableColumnResize: true,
selectedItems: $scope.mySelections,
plugins: [gridLayoutPlugin],
totalServerItems: 'totalServerItems',
columnDefs: [
{ field: 'selected', displayName: '', cellTemplate: 'checkboxcelltemplate.html', width: 25 },
{ field: 'type', displayName: 'Type', width: 41 },
{ field: 'date', displayName: 'Date', cellFilter: "date:'dd-MM-y'", width: 85 },
{ field: 'reference', displayName: 'Reference', width: 162 },
{ field: 'amount', displayName: 'Amount', cellFilter: "currency:'£'", width: 98 },
{ field: 'notes', displayName: 'Actions', cellTemplate: 'recoptions.html', width: 117 }
],
filterOptions: {
filterOptions : $scope.filterOptions,
useExternalFilter: true
},
};
}
选择选项时过滤器应该有效(没有点击任何按钮),我做错了什么?
答案 0 :(得分:0)
找到答案我可以使用的答案,但请注意,它会过滤所有匹配的列。
我将HTML中的<select>
更新为:
<select name="manualrecfilter" ng-options="choice for choice in manualrecfilter" ng-model="filterOptions.filterText" class="form-control" style="width:100% !important">
我还将控制器更新为:
$scope.filterOptions = {
filterText: ''
};
$scope.manualrecfilter = [
'Prop',
'Inv',
'Both'
];
function updategridoptions() {
$scope.gridOptions = {
data: 'myData',
rowHeight: 40,
enableColumnResize: true,
filterOptions: $scope.filterOptions,
selectedItems: $scope.mySelections,
plugins: [gridLayoutPlugin],
totalServerItems: 'totalServerItems',
columnDefs: [
{ field: 'selected', displayName: '', cellTemplate: 'checkboxcelltemplate.html', width: 25 },
{ field: 'type', displayName: 'Type', width: 41 },
{ field: 'date', displayName: 'Date', cellFilter: "date:'dd-MM-y'", width: 85 },
{ field: 'reference', displayName: 'Reference', width: 162 },
{ field: 'amount', displayName: 'Amount', cellFilter: "currency:'£'", width: 98 },
{ field: 'notes', displayName: 'Actions', cellTemplate: 'recoptions.html', width: 117 }
]
};
}