Posts Tagged applying

cellClass is an attribute which allows user to specify different styles to cells in angular UI Grid.

Problem Description:

When user tries to apply custom styling to cellClass the changes won’t get applied to UIGrid.

An important point to be noted is by design uigrid have its own css styles. These css rules comes from uigrid.css or bootstrap.css. So if a user tries to change the default style of uigrid, we need to make sure that the CSS specificity applied properly.

eg:- User is trying to change the background color of uigrid cell. uigrid already have a default cell background color ( grey / white) . So if user need to make change to background color of cell, we need to make sure that CSS Specificity is applied properly.

Solution:

Let’s have a look at CSS Specificity. When you have two or more css rules pointing to same html element, then browser follows some rules to determine which css rule is more specific and that css rule will get applied to html element. This is called CSS Specificity.

ID Selector (#Someword) : More Specificity

Class/Attribute Selector (.Someword) : Less Specificity than the ID selector.

html Selector (all) : Less Specificity than the class selector.

If you notice above list ID selector has more priority, however we can assign priority to css selector by using !important attribute.if a css value is appended with !important, it overrides all other CSS specificity and precedence will be given to the css value with !important.

Hence in order to resolve the issue user need to make sure that user defined style sheet should have more specific css rule than the default rules from uigrid.css / bootstrap.css.

For ex: below user defined css rule will not work

.cellColorChange{
background-color : 'red' ;
}

Reason is default css from ui-grd.css have more specificity. So this will take priority.