0
votes

Here is the plunker: http://plnkr.co/edit/fGVVOOIwvf4GrEj3XtJ6?p=preview

I have created a multi row grid and I would like to filter the grid data for each column header.

If I put an input box outside the grid it is working fine. If I put an input box inside the column header filtering is not working

Please see the code and help me for this.

2

2 Answers

2
votes

Use this filterBar plugin. (I cannot take credit for this, I do not remember where I found it.)

Plugin

   var filterBarPlugin = {
        init: function(scope, grid) {
            filterBarPlugin.scope = scope;
            filterBarPlugin.grid = grid;
            $scope.$watch(function() {
                var searchQuery = "";
                angular.forEach(filterBarPlugin.scope.columns, function(col) {
                    if (col.visible && col.filterText) {
                        var filterText = (col.filterText.indexOf('*') == 0 ? col.filterText.replace('*', '') : "^" + col.filterText) + ";";
                        searchQuery += col.displayName + ": " + filterText;
                    }
                });
                return searchQuery;
            }, function(searchQuery) {
                filterBarPlugin.scope.$parent.filterText = searchQuery;
                filterBarPlugin.grid.searchProvider.evalFilter();
            });
        },
        scope: undefined,
        grid: undefined,
    };

Change your header cell input ng-model to: col.filterText

<input type="text" placeholder="MY NAME" ng-model="col.filterText" ng-change="activateFilter()"/>

Add plugin to gridOptions

...
plugins: [filterBarPlugin],
...

Updated Plunker: Plunker

0
votes

I know this is old, but in case someone else ends up here...

Here is a google group thread discussing this: https://groups.google.com/forum/#!topic/angular/lhu5Fbs97G4

and within that discussion you can find the following plnkr which does what you are wanting (and which I think the above answer references): http://plnkr.co/edit/c8mHmAXattallFRzXSaG?p=preview