DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Filter Table Containing CSV Data Help Request

Open Shambles-io opened this issue 7 months ago • 2 comments

Hi there! I'm hoping to get help with part of an app I'm building.

I'm storing pretty basic inventory information in a CSV file. When this window opens, the file is read and displayed in the DPG table. I'm trying to add a text entry field to filter the table, similar to the demo. (Note: a button in a different window sets this window show=True). Additionally, it would be great to have a row selection callback for if an entry in the row needs to be updated, but I'd be happy to simply get the filtering to work lol.

Below is the code I currently have for this issue. Any help is greatly appreciated. Thanks!

with dpg.window(label="Search For NCDR Record", tag='search_win', width=750, height=500, show=False): dpg.add_text("Search for a Record by using Available Information")

dpg.add_separator()
inv_data = pd.read_csv(NCDR_PATH)

_filter_table_id = dpg.generate_uuid()
dpg.add_input_text(label="Filter", user_data=_filter_table_id, width=100, callback=lambda s, a, u: dpg.set_value(u, dpg.get_value(s)))
# filter_text = dpg.add_input_text(label="Filter", user_data='filter_input', width=100, callback=lambda s, a, u: dpg.set_value('filter_table_id', a))

with dpg.table(header_row=True, no_host_extendX=True, delay_search=True,
            borders_innerH=True, borders_outerH=True, borders_innerV=True,
            borders_outerV=True, context_menu_in_body=True, row_background=True,
            policy=dpg.mvTable_SizingFixedFit, height=300, scrollY=True, tag=_filter_table_id) as table_id:

    # Create Table Headers
    for col in inv_data.columns:
        dpg.add_table_column(label=col)

    # Add Rows
    for _, row in inv_data.iterrows():
        with dpg.table_row():
                for cell in row:
                    dpg.add_text(cell)

Shambles-io avatar Jun 04 '25 14:06 Shambles-io

Please use triple quotes around your code to format it correctly. Or, alternatively, select it and click the Code button on the formatting toolbar:

Image

v-ein avatar Jun 04 '25 18:06 v-ein

You might have noticed that the corresponding code in the demo sets filter_key on every table_row. That's how the filtering container (dpg.table in this case) understands whether to show this or that child (table_row) or not. What to put into filter_key entirely depends on your data and your purposes; I'd start with the same text as you add to every cell.

v-ein avatar Jun 04 '25 18:06 v-ein