Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't the "filterChanged" event at least return the column for which the filter has changed? #4775

Closed
Rumeth opened this issue Nov 27, 2015 · 9 comments · Fixed by #6945

Comments

@Rumeth
Copy link

Rumeth commented Nov 27, 2015

UI Grid 3.0.6

The "filterChanged" event does not currently return anything as an argument.

The document specifies the following.

filterChanged

is raised after the filter is changed. The nature of the watch expression doesn't allow notification of what changed, so the receiver of this event will need to re-extract the filter conditions from the columns.

This should mean that due to the watch expression, the old & new filter terms cannot be returned.

There seems to be only 2 instances in which the "filterChanged" event is raised.

Both of them have access to the column for which they are being raised & can be changed to the following.

restoreColumns

grid.api.core.raise.filterChanged ( currentCol );

onDownEvents

uiGridCtrl.grid.api.core.raise.filterChanged ( $scope.col );

Is there any problem returning the column for for which the filter has changed?

@imbalind
Copy link
Contributor

I cannot understand the issue. Is there a problem? Or are you suggesting an enhancement?

@Rumeth
Copy link
Author

Rumeth commented Nov 28, 2015

This can be taken as an Enhancement request.

The column argument will allow access to the changed column and also provide a way to access the grid without using "this" in strict mode.

@imbalind
Copy link
Contributor

Ok, I see.

Do you have a use case where this would advantage you?

@Rumeth
Copy link
Author

Rumeth commented Dec 1, 2015

Yes.

There is no other way to access the grid from the handler except for "this" which is given in the tutorial.

$scope.gridApi.core.on.filterChanged( $scope, function() {
         var grid = this.grid;
         if( grid.columns[1].filters[0].term === 'male' ) {
         } else if ( grid.columns[1].filters[0].term === 'female' ) {
         } else {
         }
       });

Or is there?

Using "this" in "strict" mode is not allowed.

Also, the specific column for which the filter has changed will be useful in updating the filter criteria.

$scope.gridApi.core.on.filterChanged( $scope, function(column) {
         var grid = column.grid;
         if( column.filters[0].term === 'male' ) {
         } else if ( column.filters[0].term === 'female' ) {
         } else {
         }
       });

@yesarpit
Copy link

Can someone provide workaround to find which column filter has changed on filterChanged?
I see no other way but to reset all filters before new search is performed on external filters. My backend canot filter on multiple columns and hence I need to know only the column that has changed.

@Rumeth
Copy link
Author

Rumeth commented Feb 25, 2016

@yesarpit You will have to change the following lines in the "ui-grid.js" file.

restoreColumns

grid.api.core.raise.filterChanged ( currentCol );

onDownEvents

uiGridCtrl.grid.api.core.raise.filterChanged ( $scope.col );

This will return the current column for which the filter change event is being triggered.

@yesarpit
Copy link

Thank you Rumeth for quick response, let me give it a try.Though you mentioned this solution a few months back, i thought its already patched with latest version.

@PresidentCamacho
Copy link

Hi, Is there a way you can make this change in the official tree?

@jasonbrandt42
Copy link

i second this for main code branch. And it cleans up error when multi-filters are used. Error is when last multi-filter is 'x' ed out and the grid does not return properly to a no-filter state (it filters on "" ) incorrectly.

@mportuga mportuga self-assigned this Mar 26, 2018
caseyjhol added a commit to snapappointments/ui-grid that referenced this issue Mar 13, 2019
…terChanged function

When using the filterChanged function, it's now possible to use the first argument - column - to simply do column.filters[0].term to retreive the search term for the column being filtered. This is especially useful if using external filtering.

Closes angular-ui#4775
mportuga pushed a commit that referenced this issue Apr 30, 2019
…terChanged function

When using the filterChanged function, it's now possible to use the first argument - column - to simply do column.filters[0].term to retreive the search term for the column being filtered. This is especially useful if using external filtering.

Closes #4775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants