pandastable icon indicating copy to clipboard operation
pandastable copied to clipboard

Refresh slider and rows after movetoSelection

Open Alhanz opened this issue 2 years ago • 1 comments

Hello, I am currently making database using TKinter and Pandasframe, but I started to face one small issue. I created window with all data ( over 10 000 , all working fine ) , but after I search for some term and I use "movetoSelection" , it moves me to matched term, but left indexes disappear ( I need to manually click slider to refresh them ) and slider is also not in correct position ( in a graphic way ) . I tried to refresh table, and other way to manipulate window after I moved to search result, but nothing worked in my favor. Not sure if it's because of 10 000 loaded records.

main issue is here, this is search input which will move me to match : ` def open_input_dialog_event(self):

    if self.loaded_df is None:
        tkinter.messagebox.showinfo("Search", "No data loaded. Please load data first.")
        return

    dialog = customtkinter.CTkInputDialog(text="Enter a search query:", title="Search")
    search_query = dialog.get_input().strip()

    if not search_query:
        tkinter.messagebox.showinfo("Search", "Please enter a search query.")
        return

    # Check if the search query is in the currently displayed data
    matched_rows = [
        row_index
        for row_index, row in enumerate(self.pt.model.df.itertuples(index=False), start=1)
        if any(search_query.lower() in str(val).lower() for val in row)
    ]

    if not matched_rows:
        tkinter.messagebox.showinfo("Search", "No matching records found.")
        return

    # Move to the first matched row (you can customize this behavior)
    self.pt.movetoSelection(row=matched_rows[0]-1)
    # Ensure the widget is updated and displayed
    self.pt.show()
    # Force a redraw/update of the widget
    self.pt.redraw()`

image

All code

Alhanz avatar Sep 23 '23 13:09 Alhanz

I have a similar result implementing PageUp/PageDown functionality:

        self.tableTop.bind("<Prior>",   self.handle_page_keys,  '+')       # Bind to PageUp
        self.tableTop.bind("<Next>",    self.handle_page_keys,  '+')       # Bind to PageDown
def handle_page_keys (self, event):
    """Handle PageUp/PageDown scroll for grid.  It has a problem with not updating the row (side) headers properly.  Can use up/down arrows when hitting top/bottom grid edges to redraw."""

    direction = -1 if event.keysym == 'Prior'  else 1
    table = event.widget
    table.yview_scroll (direction, tk.PAGES)
    table.rowheader.redraw()
    table.redraw()
    return 

MikeStratoti avatar Sep 27 '23 22:09 MikeStratoti