Skip to content

Commit

Permalink
fix(ui-grid-menu-button.js): Click on the menu button item checkbox … (
Browse files Browse the repository at this point in the history
…#6738)

* fix(ui-grid-menu-button.js):  Click on the menu button item checkbox weird behavior

* chore(ui-grid-menu-button): Add function for icon

Reduce duplication of code.
  • Loading branch information
vRuslan authored and mportuga committed May 31, 2018
1 parent 60d0ac9 commit c0d27d1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/js/core/directives/ui-grid-menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ angular.module('ui.grid')
function isColumnVisible(colDef) {
return colDef.visible === true || colDef.visible === undefined;
}

function getColumnIcon(colDef) {
return isColumnVisible(colDef) ? 'ui-grid-icon-ok' : 'ui-grid-icon-cancel';
}

// add header for columns
showHideColumns.push({
Expand All @@ -267,15 +271,19 @@ angular.module('ui.grid')
if ( colDef.enableHiding !== false ){
// add hide menu item - shows an OK icon as we only show when column is already visible
var menuItem = {
icon: isColumnVisible(colDef) ? 'ui-grid-icon-ok' : 'ui-grid-icon-cancel',
icon: getColumnIcon(colDef),
action: function($event) {
$event.stopPropagation();

service.toggleColumnVisibility( this.context.gridCol );

if ($event.target && $event.target.firstChild) {
$event.target.firstChild.className = isColumnVisible(this.context.gridCol.colDef) ?
'ui-grid-icon-ok' : 'ui-grid-icon-cancel';
if (angular.element($event.target)[0].nodeName === 'I') {
$event.target.className = getColumnIcon(this.context.gridCol.colDef);
}
else {
$event.target.firstChild.className = getColumnIcon(this.context.gridCol.colDef);
}
}
},
shown: function() {
Expand Down

0 comments on commit c0d27d1

Please sign in to comment.