18F / pulse

How the federal .gov domain space is doing at best practices and policies.
Other
95 stars 56 forks source link

Table search callback should be debounced? #556

Open jlas opened 8 years ago

jlas commented 8 years ago

At main.js:17 the location.hash is being updated multiple times as the user types in their query. The search function seems to work fine but clicking the back button causes the app to backtrack through each incremental search update. e.g. If the user searches for "asdf", the 1st back button click sets location.hash to "asd", the 2nd to "as", and so on.

This might easily be resolved by using a debounce function from a library like lodash, e.g.

  $('table').on('search.dt', _.debounce(function(e, settings) {
    var query = $("input[type=search]").val();
    if (query)
      location.hash = QueryString.stringify({q: query});
    ...
  }, 1000));
konklone commented 8 years ago

I totally agree. I'm not sure when this will be prioritized, but this is a constant annoyance for me as well.