Suggested changes for put_datatable()
#571
Replies: 4 comments 3 replies
-
To add buttons that don't need row to be selected for showing, I think you can use the As for |
Beta Was this translation helpful? Give feedback.
-
Pywebio provide great documentaton for creating usable feature.
|
Beta Was this translation helpful? Give feedback.
-
Here are another example to read data of datatable. It can work when row record is nested dict. def read_datatable(instance_id):
"""return the current data in the datatable"""
return eval_js("""
window[`ag_grid_${instance_id}_promise`].then(function(gridOptions) {
function unflatten_row(row) {
let result = {};
Object.keys(row).forEach((field) => {
let path = gridOptions.field2path(field);
let val = row[field];
let current = result;
for (let i = 0; i < path.length - 1; i++) {
if (!(path[i] in current)) {
current[path[i]] = {};
}
current = current[path[i]];
}
current[path[path.length - 1]] = val;
});
return result;
}
let rows = []
gridOptions.api.forEachLeafNode((row)=> rows.push(unflatten_row(row.data)))
return rows;
})""", instance_id=instance_id) Need note that: according to the aggrid doc, the grid provides simple string editing and stores the result as a string by default. |
Beta Was this translation helpful? Give feedback.
-
hi, did i miss something, was the function "get_datatable" added? would be really great, its also what i was looking for! |
Beta Was this translation helpful? Give feedback.
-
The
put_datatable()
function is a really great addition in v1.8! I have a few suggestions:I am making a table which the user will populate with rows. Currently there is no easy way to add a new row in an empty table because the actions toolbar doesn't show unless any row is selected. So, we can have an optional 3rd element in the actions tuple which specifies whether a row needs to be selected for the button to be visible.
Example:
The
False
here would signify the button available even when there are no rows, and it does not return therow_id
to the function.Add a
get_datatable(instance_id='instance_id')
type function which will return the current data in the datatable.This is helpful when we have done many changes to the datatable (adds, edits, deletes) and we want to get the current data of the datatable. It will be much easier compared to keeping separate variables with the data we updated.
Beta Was this translation helpful? Give feedback.
All reactions