Cell Renderers, value formatters, and cell styles in AgGrid (Demo) #2869
vickorian
started this conversation in
Show and tell
Replies: 3 comments 4 replies
-
Thanks for you example. I used it to show the % formatter. That's great. |
Beta Was this translation helpful? Give feedback.
1 reply
-
hello author,how do I make a column of aggrid as a button like this page https://ag-grid.com/javascript-data-grid/component-cell-renderer/ How to make 'cellrender' value as a JSclass |
Beta Was this translation helpful? Give feedback.
2 replies
-
@vickorian hello bro,can i pass a JS Function to cellStyle?Just like this: ui.add_head_html('''
<script>
function IncreaseStyle(params) {
console.log(params)
var arr = new Array("inc6","inc5","inc4","inc3","inc2","inc1");
var arrv = new Array()
for (var i =0;i<arr.length;i++){arrv.push(params.api.getValue(arr[i],params.node))}
var ownfield = params.colDef.field;
for(var i = 0;i<arrv.length-1;i++){
var frontdata = arrv[i];
var reardata = arrv[i+1];
if (frontdata==reardata && frontdata!=null){
if(ownfield==arr[i] || ownfield==arr[i+1]){background = "#FFEBCD";break;}
else{continue;}
}
else{background = "#ffffff";break;}
}
return {background: background};
}
</script>
''')
I want to change its background-color while the cell's value euqals to the last cell's value. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@rodja @falkoschindler
I'm going to be referencing these documents for examples.
AgGrid Cell-Styles
and
AgGrid Value Formatters
So i went through the .js for AgGrid that NiceGUI uses and realized that it's basically just acting as an API with very minimal bindings. Basically, that means any functions available via AgGrid are in NiceGUI so looking through some of the other examples in particular #1588 where JS was passed to echarts and i realized that passing arbitrary JS to the cells should be possible though not all of the renderers are usable in NiceGUI, like groups for some reason.
As long as you don't need to import any specific entities, it should work perfectly fine.
So for the valueformatter and cell-styles the following code is pretty straight forward.
Which renders this table.
The two biggest things are that we can pass custom functions to modify the appearance of text as well as using the build in JS functionality of AgGrid with cell-styles by interacting with the cellClassRules class instead of trying to pass an inline JS function.
I'm passing the functions and custom CSS in the ui.add_head_html() method but would like to clean it up by just referencing a file, so if anyone knows how to do that, let me know.
For basic Cell Rendering, Say we have a row of company names, then we can pass:
Where again, i've defined 'CompanyRenderer' in ui.add_head_html() with
this will create a hyperlink for any entry in the cell.
where HSL is just an arbitray word in my generated database.
These are some of the more basic things, but i'm sure someone can figure out the more complex operations. I'll keep working to try and find more customization possibilities.
Beta Was this translation helpful? Give feedback.
All reactions