Skip to content
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

Clearing search is not rendering the whole list #785

Open
StellarLogic opened this issue Jun 11, 2024 · 1 comment
Open

Clearing search is not rendering the whole list #785

StellarLogic opened this issue Jun 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@StellarLogic
Copy link

StellarLogic commented Jun 11, 2024

Clearing search is not rendering the whole list

Steps to reproduce

  1. Search for any country
  2. Then clear the search bar using the clear button inside search bar
  3. Observe whole list is not visible as search is cleared

Screenshot 2024-06-11 095335

@dosubot dosubot bot added the bug Something isn't working label Jun 11, 2024
Copy link

dosubot bot commented Jun 11, 2024

Hello @StellarLogic! I'm a bot here to help you with bugs, questions, and contributions. Let's work together to solve the issue you're facing.

To resolve the issue where clearing the search bar does not render the whole list of items in the Countries, States, and Cities columns, you need to ensure that the filter function handles the case when the search input is empty. Here is an example of how you can modify the filter function to achieve this:

function filter(type) {
  // Declare variables
  var input, filter, table, tr, td, i, txtValue;
  input = document.getElementById('search-' + type);
  filter = input.value.toUpperCase();
  table = document.getElementById(type);
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[0];
    if (td) {
      txtValue = td.textContent || td.innerText;
      if (txtValue.toUpperCase().indexOf(filter) > -1 || filter === "") {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }
  }
}

In this code, the condition txtValue.toUpperCase().indexOf(filter) > -1 || filter === "" ensures that if the search input is empty (filter === ""), all rows will be displayed. This should resolve the issue of not rendering the whole list of items when the search bar is cleared [1][2].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant