Filterrific - Persist Filter

261 Views Asked by At

I am trying to persist multiple filter settings a user sets, so that whenever a page is reloaded, or if a user navigates away and then navigates back to their filtered page, the filter settings are not reset back to the defaults. I found this question, asking for the opposite of my goal here, and inferred that setting the persistence_id to true would persist the filters, but after setting persistence_id to true for the multiple filters and navigating around my application, I found that the filters were not persisting, and instead resetting.

From how I understand filterrific's documentation, the persistence_id setting would be able to enable session persistence. Is there more to session persistence that may need to be implemented?

Rails and Ruby Versions used in our application: Rails version = 6.0.4.4 Ruby version = 2.6.8p205

Example implementation in a controller:

    def filterrific_appointments
      initialize_filterrific(
        Appointment,
        params[:filterrific],
        select_options: {
          staff_member: User.staff.map { |p| [p.full_name, p.id] },
          state: State.order(:name).pluck(:name, :id),
          with_account: [["Account Created", true], ["No Account", false]],
        },
        default_filter_params: { staff_member: current_user.id, intake: true },
        persistence_id: true,
        available_filters: %i[
          staff_member
          state
          intake
          with_account
        ],
        sanitize_params: true,
      ) || return
    end 

Example implementation in associated appointments Model:

filterrific(
    default_filter_params: { sorted_by: "start_time_asc" },
    available_filters: %i[
      sorted_by
      provider
      staff_member
      state
      appointment_type
      location
      start_time
      end_time
      with_account
    ],
  )
1

There are 1 best solutions below

0
AHaveles On

So after working with a coworkers we found that the persistence_id is not looking for a true/false value, but instead a unique string to associate the filter session with. I am assuming this is how filterrific sets these session filters in cookies such that it can differentiate the various filters.