diff --git a/src/assets/style.css b/src/assets/style.css index 9ba3c94..1a2fda5 100644 --- a/src/assets/style.css +++ b/src/assets/style.css @@ -1,10 +1,12 @@ -/* Change le texte du bout d'export */ -button.export { - font-size: 0; +/* Change la marge bout d'export */ +.table-menu { + font-size: 16px; + margin: 12px; } -button.export:before { - content: "Télécharger au format Excel"; - font-size: 14px; + +.table-menu > * { + margin: 8px; + float: left; } /* Masquer le bouton de configuration de la casse dans les filtres */ diff --git a/src/pages/home.py b/src/pages/home.py index 2f2e37c..7d8defb 100644 --- a/src/pages/home.py +++ b/src/pages/home.py @@ -11,6 +11,7 @@ from polars.exceptions import ComputeError from src.utils import ( add_annuaire_link, booleans_to_strings, + format_number, numbers_to_strings, split_filter_part, ) @@ -140,8 +141,14 @@ layout = [ id="loading-1", type="default", children=[ - html.Button("Téléchargement", id="btn-download-data"), - dcc.Download(id="download-data"), + html.Div( + [ + html.P("lignes", id="nb_rows"), + html.Button("Télécharger au format Excel", id="btn-download-data"), + dcc.Download(id="download-data"), + ], + className="table-menu", + ), datatable, ], ), @@ -151,6 +158,7 @@ layout = [ @callback( Output("table", "data"), Output("table", "data_timestamp"), + Output("nb_rows", "children"), Input("table", "page_current"), Input("table", "page_size"), Input("table", "filter_query"), @@ -160,7 +168,7 @@ def update_table(page_current, page_size, filter_query, data_timestamp): print(" + + + + + + + + + + + + + + + + + + ") global df_filtered - # 1. Apply Filters + # Application des filtres lff: pl.LazyFrame = lf # start from the original data if filter_query: filtering_expressions = filter_query.split(" && ") @@ -195,25 +203,23 @@ def update_table(page_current, page_size, filter_query, data_timestamp): # elif operator == 'datestartswith': # lff = lff.filter(pl.col(col_name).str.startswith(filter_value)") - # 2. Paginate Data + # Pagination des données start_row = page_current * page_size # end_row = (page_current + 1) * page_size # Remplacement des valeurs numériques par des chaînes de caractères lff = numbers_to_strings(lff) - dff = lff.collect() + dff: pl.DataFrame = lff.collect() df_filtered = dff.clone() + nb_rows = f"{format_number(dff.height)} lignes" dff = dff.slice(start_row, page_size) # print("dff_sliced:", lff.select("titulaire.typeId")) - dff = dff.to_dicts() + dicts = dff.to_dicts() - return ( - dff, - data_timestamp + 1, - ) # update data, update timestamp + return dicts, data_timestamp + 1, nb_rows # update data, update timestamp @callback( diff --git a/src/utils.py b/src/utils.py index 7fc1d14..2bf785a 100644 --- a/src/utils.py +++ b/src/utils.py @@ -64,3 +64,8 @@ def numbers_to_strings(lf: pl.LazyFrame) -> pl.LazyFrame: """ lf = lf.with_columns(pl.col(pl.Float64, pl.Int16).cast(pl.String).fill_null("")) return lf + + +def format_number(number) -> str: + number = "{:,}".format(number).replace(",", " ") + return number