Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
12.15k stars 875 forks source link

Add formatting in tables using functions #564

Closed chrisOnWheels closed 1 week ago

chrisOnWheels commented 1 year ago

Currently Taipy uses printf style formatting in tables

<|table|data={my_data}|columns={col_format}|...|>
col_format = {'Sales':'%.2f'}

This could be extended by allowing functions, like in <|selector|adapter={...}>

col_format={ "Sales": {"format_function": format_func}}

def format_func(data, column_name) -> list[str]:
    ... apply formatting ...
    return formatted_column_data

Such functions might even return images

Background:
I'd like to have floats formatted like 9.999,99 which seems not possible using pure printf style syntax in Taipy. Taipy doesn't support %'d to get locale aware thousands separator. AFAIK printf doesn't support thousands separators in floats.

FlorianJacta commented 1 year ago

Thank you for your issue! It seems like a good feature! We will talk about it inside our R&D team

yaten2302 commented 3 months ago

Hey @FlorianJacta, is this feature required, may I give it a try to add this?

FlorianJacta commented 3 months ago

@FabienLelaquais @FredLL-Avaiga Could this issue be assigned?

FabienLelaquais commented 3 months ago

It certainly can. The thing is, it is far more complicated than it looks since the conversion to string has to be performed on the server side, which is going to be a problem. Especially for the edition part. But hey, let's move forward yes.

yaten2302 commented 3 months ago

Hey @FabienLelaquais @FlorianJacta , I've a doubt in this, like instead of letting the user provide the format function, can we provide our own format functions? like, we can have some functions which renders a specific number of rows that the user requires or something like that?

If the user passes the format function, then will it be possible to implement that?

FlorianJacta commented 2 months ago

I am not sure I understand your issue @yaten2302. We want a function that converts all values of the rows of a column into other values that will be the ones displayed.

yaten2302 commented 2 months ago

@FlorianJacta actually, I'm not completely able to understand this? Could you please explain this once again - "We want a function that converts all values of the rows of a column into other values that will be the ones displayed."?

FlorianJacta commented 2 months ago

We want to use a user function to format column values. Just, like the example written in the issue.

Maybe you already understand it this way, and I am just overcomplicating it.