Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/features/grouping/js/grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

grid.registerRowsProcessor(service.groupRows, 400);

grid.registerColumnsProcessor(service.groupingColumnProcessor);
grid.registerColumnsProcessor(service.groupingColumnProcessor, 400);

/**
* @ngdoc object
Expand Down
33 changes: 30 additions & 3 deletions src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,26 @@ angular.module('ui.grid')
*/
self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor );

/**
* @ngdoc function
* @name registerColumnsProcessor
* @methodOf ui.grid.core.api:PublicApi
* @description
* Register a "columns processor" function. When the columns are updated,
* the grid calls each registered "columns processor", which has a chance
* to alter the set of columns as long as the count is not
* modified.
*
* @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which
* is run in the context of the grid (i.e. this for the function will be the grid), and must
* return the updated columns list, which is passed to the next processor in the chain
* @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
* for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
*
* At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
*/
self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor );



/**
Expand Down Expand Up @@ -1316,18 +1336,25 @@ angular.module('ui.grid')
* is run in the context of the grid (i.e. this for the function will be the grid), and
* which must return an updated renderedColumnsToProcess which can be passed to the next processor
* in the chain
* @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
* for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
*
* At present all rows visible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
* @description

Register a "columns processor" function. When the columns are updated,
the grid calls each registered "columns processor", which has a chance
to alter the set of columns, as long as the count is not modified.
*/
Grid.prototype.registerColumnsProcessor = function registerColumnsProcessor(processor) {
Grid.prototype.registerColumnsProcessor = function registerColumnsProcessor(processor, priority) {
if (!angular.isFunction(processor)) {
throw 'Attempt to register non-function rows processor: ' + processor;
}

this.columnsProcessors.push(processor);
this.columnsProcessors.push({processor: processor, priority: priority});
this.columnsProcessors.sort(function sortByPriority( a, b ){
return a.priority - b.priority;
});
};

Grid.prototype.removeColumnsProcessor = function removeColumnsProcessor(processor) {
Expand Down Expand Up @@ -1363,7 +1390,7 @@ angular.module('ui.grid')
// the result.
function startProcessor(i, renderedColumnsToProcess) {
// Get the processor at 'i'
var processor = self.columnsProcessors[i];
var processor = self.columnsProcessors[i].processor;

// Call the processor, passing in the rows to process and the current columns
// (note: it's wrapped in $q.when() in case the processor does not return a promise)
Expand Down
4 changes: 2 additions & 2 deletions src/js/core/services/gridClassFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
});

return columns;
});
}, 50);

grid.registerColumnsProcessor(function(renderableColumns) {
renderableColumns.forEach(function (column) {
Expand All @@ -71,7 +71,7 @@
});

return renderableColumns;
});
}, 50);


grid.registerRowsProcessor(grid.searchRows, 100);
Expand Down
10 changes: 3 additions & 7 deletions test/unit/core/row-filtering.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,15 @@ describe('rowSearcher', function() {

var ret = rowSearcher.search(grid, rows, columns);

expect(ret[0].visible).toBe(false);
expect(ret[1].visible).toBe(true);
expect(ret[2].visible).toBe(true);
expect(ret.length).toBe(2);
});

it('should filter by 0', function() {
setFilter(columns[2], 0);

var ret = rowSearcher.search(grid, rows, columns);

expect(ret[0].visible).toBe(false);
expect(ret[1].visible).toBe(false);
expect(ret[2].visible).toBe(true);
expect(ret.length).toBe(1);
});
});

Expand All @@ -252,7 +248,7 @@ describe('rowSearcher', function() {

var ret = rowSearcher.search(grid, rows, columns);

expect(ret.length).toEqual(2);
expect(ret.length).toEqual(3);
});
});

Expand Down