I am using angularjs ui grid api. I have created a single html input tag to apply a filter to all columns based on the users input. I want to filter each column then combine the results into a single ui grid
I have tried to loop through each column and apply the text filter from the input tag to all columns. This however looks for a row in the ui grid that has the text from the input tag in all columns. I want to display all rows that have at least one column that contains the filter string not all rows that contain the filter string in all columns
angular.module('main') .controller('mainCtrl', function($scope, $filter, uiGridConstants) {
// ********************************************
// ui-grid configuration and functionality
// ********************************************
$scope.atlasUserMonitorGrid = {
enableSorting: true,
enableFiltering: true,
enableGridMenu: true,
enableColumnMenus: false,
// pagination settings
paginationPageSizes: [1, 2, 5, 10],
paginationPageSize: 5,
// Dummy test data
data: [
{counter: 1, username: 'bob27', last_view: '27/12/2018', total_views: 48, group: 'group 1', data_view: 32, records: 3, crosstabs: 8, reports: 5, explorer: 3, bookmarks: 2},
{counter: 2, username: 'sarah01', last_view: '04/01/2019', total_views: 8, group: 'group 2', data_view: 2, records: 2, crosstabs: 7, reports: 4, explorer: 2, bookmarks: 12},
{counter: 3, username: 'jono0501', last_view: '09/01/2019', total_views: 33, group: 'group 1', data_view: 12, records: 7, crosstabs: 4, reports: 18, explorer: 78, bookmarks: 44},
{counter: 4, username: 'peterh', last_view: '21/01/2019', total_views: 33, group: 'group 3', data_view: 111, records: 12, crosstabs: 6, reports: 55, explorer: 9, bookmarks: 5},
{counter: 5, username: 'joe201', last_view: '11/02/2019', total_views: 34, group: 'group 1', data_view: 3, records: 17, crosstabs: 24, reports: 128, explorer: 178, bookmarks: 144},
{counter: 6, username: 'amy_mcN', last_view: '25/01/2019', total_views: 65, group: 'group 2', data_view: 212, records: 27, crosstabs: 14, reports: 718, explorer: 278, bookmarks: 244},
{counter: 7, username: 'ke', last_view: '15/02/2019', total_views: 1156, group: 'group 3', data_view: 1124, records: 47, crosstabs: 64, reports: 17, explorer: 378, bookmarks: 344},
],
columnDefs: [
{
field: 'counter',
displayName: '',
name: 'Counter',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: false,
enableFiltering: false,
width: 45
},
{
field: 'username',
displayName: 'Username',
name: 'Username',
type: 'string',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
term: ''
}
},
{
field: 'last_view',
displayName: 'Last View',
name: 'Last View',
type: 'date',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
},
{
field: 'total_views',
displayName: 'Total Views',
name: 'Total Views',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
},
{
field: 'group',
displayName: 'Group',
name: 'Group',
type: 'string',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
term: ''
}
},
{
field: 'data_view',
displayName: 'Data View',
name: 'Data View',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
},
{
field: 'records',
displayName: 'Records',
name: 'Records',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
},
{
field: 'crosstabs',
displayName: 'Crosstabs',
name: 'Crosstabs',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
},
{
field: 'reports',
displayName: 'Reports',
name: 'Reports',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
},
{
field: 'explorer',
displayName: 'Explorer',
name: 'Explorer',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
},
{
field: 'bookmarks',
displayName: 'bookmarks',
name: 'bookmarks',
type: 'number',
sortDirectionCycle: [uiGridConstants.ASC, uiGridConstants.DESC],
enableSorting: true,
enableFiltering: true,
filter: {
condition: uiGridConstants.filter.EXACT
}
}
],
};
// ********************************************
// Filtering configuration and functionality
// ********************************************
$scope.filterGrid = function(filterValue) {
// Looping through all columns that have filtering enabled
// and are of type string
for (var i = 0; i < $scope.atlasUserMonitorGrid.columnDefs.length; i++) {
if ($scope.atlasUserMonitorGrid.columnDefs[i].enableFiltering == true
&& $scope.atlasUserMonitorGrid.columnDefs[i].type === "string") {
// setting term variable in the columnDefs filter object to equal
// the filterValue passed into the function
$scope.atlasUserMonitorGrid.columnDefs[i].filter.term = filterValue;
}
}
}
filterBy: bo ui-grid
name group
bob group1
john group2
amy bobo_group
expected results:
result
name group
bob group1
amy bobo_group
actual results:
name group
* empty *
This is because the filtering is looking for a row that contains the string "bo" in the name and group column. I want it to filter the ui grid if it has the string "bo" in the name or group column.