leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
536 stars 215 forks source link

Auto Reload Only Works Once? #330

Open BagpipesJohnson opened 7 years ago

BagpipesJohnson commented 7 years ago

I am hoping that I am not barking up the wrong tree--

I am working with a SIMPLE wice grid to filter descriptions (Which are strings)

The first time I change the filter, the page reloads and everything is alright--after that point, I can change the drop down and nothing happens. I click on reset filter and nothing happens either. I have checked and see that JQuery is indeed loaded along with all of wice grid js files.

I have attached the files I would imagine you would need:

View:

'<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

<%= grid(@conversation_grid, show_filters: :always) do |g|
  g.column name:  'Description', attribute: 'description', auto_reload: true, custom_filter: :auto
  end -%>

<%= link_to 'New Conversation', new_conversation_path, {class: "btn btn-info"} %>`

Controller:

`def index
    @conversations = Conversation.all
    @conversation_grid = initialize_grid(Conversation)
    @current_user  = UserUtils.get_current_employee_observer(session)
  end`

Application.js:

`// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require bootstrap-sprockets
//= require bootstrap
//= require jquery_ujs
//= require jquery-ui
//= require wice_grid
//= require jquery-ui/datepicker
//= require_tree .
//= require turbolinks
//= require Chart.bundle
//= require chartkick
//= require_tree .

function remove_fields(link, row) {
  $(link).prev("input[type=hidden]").val("1");
  $(row).hide()
}

function add_fields(link, association, content, table) {
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + association, "g")
  var row = $('#' + table + " tr:nth-last-child(1)")
  row.before(content.replace(regexp, new_id));

}`

Many thanks

BagpipesJohnson commented 7 years ago

I also turned off auto reload and tried to reload by clicking the filter item and it is unresponsive. Also unable to show/hide filters when changing "Filter Always" to "When Filtered"

cedricdeschenes commented 7 years ago

I know this issue is kinda old and I won't really provide a solution, but it seems like the problem is with Turbolinks, if you turn it off, you should be able to use the filters again.

I hope this might help you!

patricklindsay commented 6 years ago

This is fixed in master but a release hasn't been cut for it.

As a work around you can call initWiceGrid() yourself;

document.addEventListener("turbolinks:load", function() {
  initWiceGrid();
});