问题描述:使用 AngularJS 1.8.3 版本和 UI-Grid 4.x 版本时,如果在 UI Grid 中启用了行选择,会导致选中行的高度变化。这样会影响到整个页面的布局和样式。这是因为 UI Grid 在选中行时会自动添加选中行的样式,其中包括行高。
解决方法如下:
.ui-grid-row.selected .ui-grid-cell { background-color: #337ab7; color: #fff; height: inherit !important; }
$scope.gridOptions.onRegisterApi = function(gridApi) { $scope.gridApi = gridApi;
gridApi.selection.on.rowSelectionChanged($scope,function(row){
if(row.isSelected){
angular.element(document.querySelectorAll('.ui-grid-selection-row-header-buttons')).addClass('selected');
row.grid.cellNav.clearFocus();
} else {
angular.element(document.querySelectorAll('.ui-grid-selection-row-header-buttons')).removeClass('selected');
}
});
};
这样,当用户选择一行时,会自动添加选中行的样式,并且选中行的高度会继承父级元素的高度。
通过这个方法,您可以轻松地解决使用 AngularJS 1.8.3 和 UI-Grid 4.x 版本时出现的 UI Grid选择动态行高问题。
上一篇:Angularjs1.8.2npmrunprodisnotworking
下一篇:AngularJS1.x中是否有类似于jQuery中的$(element).click()实现点击事件的方法?如果有的话,该方法的使用方法是什么?