-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Unserializable object for ipyaggrid table cell renderer #70
Comments
Hi @AlesyaSeliazniova30032012, You can't use python code here, it has to be JavaScript (see this and this). Example: 'cellRenderer': """__js__:
class {
init(params) {
const poundFormat = new Intl.NumberFormat('en-GB', {
style: 'currency',
currency: 'GBP',
});
const eGui = this.eGui = document.createElement('span');
eGui.innerHTML = poundFormat.format(params.value);
}
getGui() {
return this.eGui;
}
}
""" if column in currency_columns else None |
Oh.. I've never encountered JS. We need to figure it out. Thanks, it worked. |
Or maybe there is some alternative to this code for Python? |
maybe you can tell me what I wrote wrong here, because I don't own js. I want to change the style of the cells depending on the sign. Thanks 'cellClass': """__js__:
class {
init(params) {
const eGui = this.eGui = document.createElement('span');
if (params.value < 0) {
eGui.classList.add('negative-value');
} else if (params.value > 0) {
eGui.classList.add('positive-value');
}
}
getGui() {
return this.eGui;
}
}""", And where do I need to apply these styles?
|
A cellRenderer is run on the browser where only JavaScript is available. You could set the formatted text in the dataframe instead of the raw numbers, that can be done in Python. |
In this example |
Worked for me. Thanks |
Hi. I use "ipyaggrid" lib. I want to convert all price values to float format with 2 decimal places and add a prefix £. Please tell me what I'm doing wrong and how to fix it, that I'm getting an error TypeError: Unserializable object <function currency_renderer at 0x0000026B9F46AB60> of type <class 'function'>. Thanks for any help
def currency_renderer(params): formatted_value = "£{:.2f}".format(float(params.value)) return formatted_value
`
def create_aggrid(df):
currency_columns = ['size', 'pnl', 'commission']
column_defs = [
{
'headerName': column,
'field': column,
'cellRenderer': currency_renderer if column in currency_columns else None
}
for column in df.columns
]
grid_options = {
'columnDefs' : column_defs,
'defaultColDef': {'sortable': 'true', 'filter': 'true', 'resizable': 'true'},
}
`
The text was updated successfully, but these errors were encountered: