Skip to content

Multiple onColumnSearch events when user has not touched the filter field #7726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hepcat72 opened this issue Feb 13, 2025 · 0 comments
Open
Labels
filter-control Issues for the filter-control extension. help-wanted Issues we need or would love help from the community to resolve.

Comments

@hepcat72
Copy link
Contributor

Description

I have an issue that seems related to #1605. The onColumnSearch fires an event on page load. To work around it, I used a "loading" variable that I update after a timeout to prevent the repeated page load. Why do I have to do this and how can I make this work-around unnecessary?

Example(s)

        document.addEventListener("DOMContentLoaded", function(){
            var loading = true;

            $('#file_list').bootstrapTable({
                onColumnSearch: function (columnName, searchTerm) {
                    if (!loading) {
                        // NOTE: I will have to populate the column searches on page load
                        // NOTE: Turns out that one page load, a column search event is triggered, so we check to see if anything changed before triggering a page update.
                        let oldTerm = getCookie('archive-file-filter-' + columnName);
                        let oldTermDefined = typeof oldTerm === "undefined" || !oldTerm;
                        let newTermDefined = typeof searchTerm === "undefined" || !searchTerm;
                        if (oldTermDefined !== newTermDefined || (oldTermDefined && newTermDefined && oldTerm !== searchTerm)) {
                            setCookie('filter-' + columnName, searchTerm);
                            console.log("COLUMN SEARCH EVENT:", columnName, searchTerm);
                            updatePage();
                        }
                    }
                },
            });

            setTimeout(function () {loading = false}, 2000);
        });

As you can see, I already suppressed multiple repeated loads by checking the search term against the previous search term.

I'm in the middle of developing this page and I have not yet set the searched term on page load, so could this be that BST is keeping track and sees the empty field and assumes it's a new search, thus triggering the reload?

@hepcat72 hepcat72 added the help-wanted Issues we need or would love help from the community to resolve. label Feb 13, 2025
@wenzhixin wenzhixin added the filter-control Issues for the filter-control extension. label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filter-control Issues for the filter-control extension. help-wanted Issues we need or would love help from the community to resolve.
Projects
None yet
Development

No branches or pull requests

2 participants