I have a ui-grid table which has been implemented with Server-side filtering, now i have a scenario that i am passing the filtering term in my api from another page and coming to the ui-grid page with the filtered data for the grid but the selection of the filter for that column is not applied.
Code:
$scope.gridOptions = {
enableSelectAll: false,
exporterCsvFilename: fileNm,
exporterMenuPdf: false,
enableFiltering: true,
showGridFooter: true,
paginationPageSizes: [25, 50, 75],
paginationPageSize: 25,
useExternalPagination: true,
enableGridMenu: true,
..
..
.
Sample columnDef
var sparableColumn = {
name: 'sparable', displayName: 'Sparable', headerCellClass: $scope.highlightFilteredHeader,
filter: {
type: uiGridConstants.filter.SELECT,
selectOptions: $scope.sparableFilter
},
cellTemplate:'<div ng-if="row.entity.sparable" class="tcenter">{{row.entity.sparable}}</div><div ng-if="!row.entity.sparable"></div>',
cellClass: function (grid, row, col) {
if (grid.getCellValue(row, col) === 'NO') {
return 'red tcenter';
}
if(grid.getCellValue(row, col) === 'YES') {
return 'green tcenter';
}
return 'tcenter';
}
};
Server side filter inside onRegisterApi:
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.core.on.filterChanged( $scope, function() {
var grid = this.grid;
$scope.serversideFilters = [];
angular.forEach(grid.columns, function(value, key) {
if(value.filters[0].term) {
var dummy = {};
console.log('FILTER TERM FOR ' + value.colDef.name + ' = ' + value.filters[0].term);
dummy['k'] = value.colDef.name;
dummy['v'] = value.filters[0].term;
$scope.serversideFilters.push(dummy);
}
});
getPage();
});
I know we need to populate or select it via grid.columns.filters but how and where to put the code to activate the filtered column selection is the question.
Thanks in advance!