Best way to filter null values ​​with angular -ui-grid?

I would like to offer my users the ability to show only rows with empty values ​​for a specific column. What would be a better approach? I came up with this solution that seems hacked to me by reusing the filter input text box:

"onRegisterApi" : function(gridApi){ $scope.gridApi = gridApi; $scope.gridApi.core.on.filterChanged( $scope, function() { var grid = this.grid; var term = grid.columns[7].filters[0].term; // the column I am interested in empty values if( term == '_' ) { $log.info("Setting filter to external mode"); $scope.grid.useExternalFiltering = true; for(var i=0; i< grid.rows.length;i++){ var row = grid.rows[i]; if(row.entity.privileges==null || row.entity.privileges.trim().length==0){ $scope.gridApi.core.clearRowInvisible(row); } else{ $scope.gridApi.core.setRowInvisible(row); } } }else if($scope.grid.useExternalFiltering==true){ $log.info("Resetting filter back to internal mode"); $scope.grid.useExternalFiltering = false; for(var i=0; i< grid.rows.length;i++){ $scope.gridApi.core.clearRowInvisible(grid.rows[i]); } } }); } 
+5
source share

Source: https://habr.com/ru/post/1215995/


All Articles