1

|number | 1 3 4|

For example , I need to show "1" as red , "3" as green . they are in the same cell . i know i can use cell class to change the whole data color in one cell . but that 's not what i want .

Could you please give me some clues to work it out ? or is this any other way to do this ,like Angular UI or using other libraries .

Thanks

1

1 Answer 1

2

I suspect this isn't so much a ui-grid thing, as being a general question of how you render data with in angular colours.

I would probably do this with a custom cellTemplate, and some sort of ng-style. The question is how your data is arriving in the cell - so are the 1 3 4 coming from the cell value, or do you have something else going on?

Assuming that they are in the cell value, then you'd probably need something like

<div ng-style="grid.appScope.setStyle(grid.appScope.left(COL_FIELD)>grid.appScope.left(COL_FIELD)</div>
<div ng-style="grid.appScope.setStyle(grid.appScope.mid(COL_FIELD)>grid.appScope.mid(COL_FIELD)</div>
<div ng-style="grid.appScope.setStyle(grid.appScope.right(COL_FIELD)>grid.appScope.right(COL_FIELD)</div>

Where - setStyle is a function on your scope that takes in a number and decides what style to apply to it - left gets the leftmost number from your data - mid gets the middle number from your data - right gets the rightmost number from your data

If your input structures are different then there are other ways to use cellTemplates to get the result you want.

EDIT: Based on the further information, I think you'll want to render your string as html, and then parse that html into the cell. I think this is then more a broader question of "how can angularJS render arbitrary HTML for me", and the answer may be ng-bind-html, although I don't know much about it. In theory that would let you create your markup in html, then bind that resulting markup into the cell by using ng-bind-html='COL_FIELD' in the cellTemplate.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi . Thanks PauIL , It received data from Rest Api , Basically i want to show the difference between two rows. i am not sure how many stuff in one cell .but it supposed to be a list . i plan to show stuff(new) as green . item (deleted) as red .
OK, so you're parsing the string to do a diff, and highlighting different parts of the string. I think this approach I suggested won't work because you'll need a differing number of divs or spans depending on what your result looks like.
Hey , i solved it by imbedding divs into cellTemplates, actually this 's the same idea with you . thanks ! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.