[英]Filter array of object in AngularJs UI Grid
In AngularJS UI Grid, I receive JSON object and bind it to a grid. 在AngularJS UI Grid中,我接收JSON对象并将其绑定到网格。 Now I want to filter rows based on multiple conditions from some checkboxes.
现在我想根据一些复选框中的多个条件来过滤行。
For example, I have 3 checkboxes for time: 例如,我有3个时间复选框:
10:00 - 12:00 -- checkbox
14:00 - 18:00 -- checkbox
20:00 - 23:00 -- checkbox
If the user clicks on the 10:00 - 12:00
and 14:00 - 18:00
checkboxes, the row should filtered based on those times. 如果用户单击
10:00 - 12:00
和14:00 - 18:00
复选框,则应根据这些时间对该行进行过滤。
$scope.filterGrid = function(value) {
for (int i = 0; i <= $scope.gridApi.grid.columns[2].rows.entity.length(); i++) {
// I put one condition here as an example, but in my code all of the conditions
// are included
if ($scope.gridApi.grid.columns[2].rows.entity[i].time >= "14:00" &&
$scope.gridApi.grid.columns[2].rows.entity[i].time <= "18:00") {
$scope.gridApi.grid.columns[2].filters[0]={term:value};
}
}
};
In my code, I can get what the object contains in the time ranges, but when I add objects into the grid, I only ever get last added object. 在我的代码中,我可以获得对象在时间范围中包含的内容,但是当我将对象添加到网格中时,我只获得最后添加的对象。 For example, if I have 4 objects, the grid always show the 4th object.
例如,如果我有4个对象,则网格始终显示第4个对象。
I think rather than adding objects, I am overwriting them. 我想,不是添加对象,而是覆盖它们。 How can I solve this problem?
我怎么解决这个问题?
Thank you for your help. 谢谢您的帮助。
you have to change: 你必须改变:
$scope.gridApi.grid.columns[2].filters[0]={term:value};
to: 至:
$scope.gridApi.grid.columns[2].filters[i]={term:value};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.