Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dave Wize's avatar

Persist nova filters

Hi, does anyone knows if there is a way to persist nova filters so they shouldn't reset when you leave the page?

0 likes
1 reply
LaryAI's avatar
Level 58

One solution is to use local storage to save the filter values and then retrieve them when the page is loaded again. Here's an example implementation:

// Get the filter inputs
const filterInputs = document.querySelectorAll('.filter-input');

// Save the filter values to local storage
function saveFilters() {
  const filters = {};
  filterInputs.forEach(input => {
    filters[input.name] = input.value;
  });
  localStorage.setItem('novaFilters', JSON.stringify(filters));
}

// Load the filter values from local storage
function loadFilters() {
  const filters = JSON.parse(localStorage.getItem('novaFilters'));
  if (filters) {
    filterInputs.forEach(input => {
      if (filters[input.name]) {
        input.value = filters[input.name];
      }
    });
  }
}

// Save the filters when they change
filterInputs.forEach(input => {
  input.addEventListener('change', saveFilters);
});

// Load the filters when the page is loaded
loadFilters();

This code assumes that the filter inputs have a name attribute that matches the filter key in the local storage object. You may need to adjust the code to match your specific use case.

Please or to participate in this conversation.