lundi 28 janvier 2019

Filterrific not filtering data

I am trying to use Filterrific gem to filter data. but seems like every time I type in the text field, it just refreshes page and filter. I don't want it to refresh the page and it should be instant.

Controller:

  def index
    dictionary_types = DimDictionary::DISPLAY_TYPE.map{|key, value| value }
    @dictionary_types_array = DimDictionaryType.where(dictionary_type_name: dictionary_types).pluck(:dictionary_type_name, :dictionary_type_id)
    @filterrific = initialize_filterrific(
      fetch_dictionary_collection,
      params[:filterrific],
      select_options: {},
      persistence_id: 'shared_key',
      default_filter_params: {},
      available_filters: [
          :dictionary_word_filter
        ],
    ) || return

    @dictionaries = @filterrific.find

    respond_to do |format|
      format.html
      format.js
    end
  end

Created three files:

Index.html.haml

= form_for_filterrific @filterrific do |f|
  .ui.form
    .fields
      .field
        Filter Word
        = f.text_field :dictionary_word_filter

  = render_filterrific_spinner

= render(partial: 'test/list', locals: { dictionaries: @dictionaries, dictionary_types_array: @dictionary_types_array })

Index.js.erb

<%  js = escape_javascript(render(partial: 'test/list', locals: { dictionaries: @dictionaries, dictionary_types_array: @dictionary_types_array })) %>

$("#filterrific_results").html("<%= js %>");

_list.html.haml

#filterrific_results
  %strong Test Is Working
  %table.table.dictionary-table
    %thead
      %tr
        %th #
        %th Type
        %th Word
        %th Replacement
    %tbody#dictionary-content-area.clusterize-content
      - counter = 0
      - dictionaries.each do |dictionary|
        - counter = counter + 1
        %tr{ data: {id: dictionary.dictionary_id, index: counter, type: dictionary.dim_dictionary_type.dictionary_type_id}}
          %td
            = counter
          %td#dictionary-type
            = dictionary.dim_dictionary_type.dictionary_type_name
          %td#original-word
            = dictionary.dictionary_word
          %td#replaced-word
            = dictionary.dictionary_replacement

Am I doing something wrong here? This is all I have added.

Aucun commentaire:

Enregistrer un commentaire