Reputation: 2046
I'm creating a search input that will search individual fields/columns in an ng-grid. (yes, I know ng-grid has its own way of doing this.)
I've got the search working, and I can search on individual fields, but the one piece I can't seem to figure out is how to re-trigger a search upon selecting a new field from the dropdown.
So: user searches fields 'Name' for 'blah', and gets some results. Then user decides to search field 'Age'. Search should immediately return any records that have 'blah' in the 'Age' field.
Here is my plunker: http://plnkr.co/edit/Ryjp2ugmYWHcfvNdD7OZ?p=preview
(Try searching for 'ni' in the name field, then in the Age field. Ideally, I want to search Name to get Moroni, and then Age to get twenty nine). You can search on any field - as long as you choose the field FIRST - changing the field AFTER typing some search text doesn't work. In fact, I can't really seem to clear the search at all.
This part is my clumsy attempt to re-trigger the grid rendering, but I do not know where 'grid' and '$gridScope' come from:
$scope.reSearch = function(){
$scope.gridInit(grid, $gridScope);
};
(You can see that I'm using gridInit. My page is pretty complex so I can't simplify the plunker any more than I have.)
Upvotes: 0
Views: 216
Reputation: 2654
I advanced your code to the point that reSearch successfully calls gridInit again: http://plnkr.co/edit/28bF6QBdRtfywA0YmUoV?p=preview
However, in this line, you are trashing your original data, so when you search again, you are only searching through the last search's results:
$scope.myData = grid.filteredRows;
Upvotes: 1