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

No way to programmatically unfocus CellNav cells when data and columns change #3815

Closed
StarFi55ure opened this issue Jun 19, 2015 · 8 comments

Comments

@StarFi55ure
Copy link

Im not sure if there's a way to do this. I update the grid with new data and new columns but the CellNav selection persists even after I call refresh or notifyDataChange with ALL constant.

I tried setting focusedCells = [], but that didnt work. Calling $scope.gridApi.cellNav.scrollToFocus(null, null) also didnt work.

@JLLeitschuh
Copy link
Contributor

This should get you what you want
if (document.activeElement != document.body) document.activeElement.blur();
Source: http://stackoverflow.com/questions/2520650/how-do-you-clear-the-focus-in-javascript

@StarFi55ure
Copy link
Author

Unfortunately, this doesn't work. The selected cell still remains selected.

@JLLeitschuh
Copy link
Contributor

This is the line creating the problem. https://github.com/angular-ui/ng-grid/blob/master/src/features/cellnav/js/cellnav.js#L940
It is because the event type in the event never gets set.
See the documentation here: https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$on
This was added in aabcd4d

JLLeitschuh referenced this issue Jun 30, 2015
Shift-tabbing at top-left and tabbing at bottom right will now all tabbing
out of the grid to the next/previous element.

This doesn't fix all the problems with cellnav but it shuld fix this one.

Fixes #2339
@JLLeitschuh JLLeitschuh assigned JLLeitschuh and unassigned c0bra Jun 30, 2015
JLLeitschuh added a commit that referenced this issue Jul 20, 2015
As you navigate the grid using cell nav the browser should now read out
the cell that is currently focused.

Fixes #3896
Partially resolves #3815
JLLeitschuh added a commit to JLLeitschuh/ui-grid that referenced this issue Jul 20, 2015
As you navigate the grid using cell nav the browser should now read out
the cell that is currently focused.

Fixes angular-ui#3896
Partially angular-ui#3815
JLLeitschuh added a commit to JLLeitschuh/ui-grid that referenced this issue Jul 22, 2015
As you navigate the grid using cell nav the browser should now read out
the cell that is currently focused.

Fixes angular-ui#3896
Partially angular-ui#3815
JLLeitschuh added a commit to JLLeitschuh/ui-grid that referenced this issue Jul 27, 2015
As you navigate the grid using cell nav the browser should now read out
the cell that is currently focused.

Fixes angular-ui#3896
Partially angular-ui#3815
JLLeitschuh added a commit to JLLeitschuh/ui-grid that referenced this issue Jul 27, 2015
As you navigate the grid using cell nav the browser should now read out
the cell that is currently focused.

Fixes angular-ui#3896
Partially angular-ui#3815
@andrew2net
Copy link

This work for me:

var dataCopy = $scope.data;
$scope.data = [];
$timeout(function(){ $scope.data = dataCopy; });

@andrew2net
Copy link

I made couple functions in cellNav module:

/*
* Remove focus.
* @return {void}
*/
gridApi.cellNav.clearFocus();

/*
* Set focus on cell in row/col position.
* @param {integer} rowIndex - Index of row.
* @param {GridColumn} col - Column object.
* @return {void}
*/
gridApi.cellNav.setFocus(rowIndex, col);

you can get modified code from: https://github.com/andrew2net/ui-grid.git

@bazizten
Copy link

Don't know if it is exactly this you are after but it solved my problems :)
Somewhat hacky but here it is:

gridApi.grid.cellNav.clearFocus(); //To get rid of the highlighting
gridApi.grid.cellNav.focusedCells = []; //To clear all focused cells

@jbougaev
Copy link

jbougaev commented Mar 31, 2017

@bazizten We have the same issue (the same as described here). Could you please tell where did you add the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants