leikind / wice_grid

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

Silent filter failure, cause unknown #198

Closed HazelGrant closed 9 years ago

HazelGrant commented 9 years ago

My current problem:

wice_grid filtering is not working.

in development, I can get the icons to show up. they are clickable but nothing is activated when clicking them. the page does not respond in any way. (by clickable, I mean, my cursor changes from arrow-pointer to hand-pointer. so at least some javascript is working…)

I followed the directions in the documentation. Here's how the code is implemented in my code base:

Gemfile

gem 'wice_grid', '3.4.2'

I called bundle install and the generator. wice_grid_config.rb, wice_grid.yml, and wice_grid.css.scss have all been generated and I can find them easily.

My application.js file:

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require vendor-javascripts

And then vendor-javascripts:

…other vendor javascripts
//= require wice_grid
//= require jquery-ui/datepicker

wice_grid.css.scss is included in vendor-stylesheets which is included in application.css, similarly.


I have several tables. They all include at least one filterable/sortable column. Sorting is working just fine. This is a JavaScript issue.


There are no errors in the browser console.

In my application header on the page, the wice_grid js files show up as follows:

<script src="/assets/wice_grid_processor.js></script>
<script src="/assets/wice_grid_init.js></script>
<script src="/assets/wice_grid_saved_queries_init.js></script>
<script src="/assets/wice_grid.js></script>

jQuery is loaded before wice_grid and is definitely present.

And yet the filtering button simply does not respond when clicked, on any of my tables.


in the console, when I type

WiceGridProcessor

I get

 function WiceGridProcessor(name, baseRequestForFilter, baseLinkForShowAllRecords, linkForExport, parameterNameForQueryLoading, parameterNameForFocus, environment) {
      this.name = name;
      this.baseRequestForFilter = baseRequestForFilter;
      this.baseLinkForShowAllRecords = baseLinkForShowAllRecords;
      this.linkForExport = linkForExport;
      this.parameterNameForQueryLoading = parameterNameForQueryLoading;
      this.parameterNameForFocus = parameterNameForFocus;
      this.environment = environment;
      this.filterDeclarations = new Array();
      this.checkIfJsFrameworkIsLoaded();
    }

Have read this issue and found no explanation or solution. The only other somewhat related post I've come across is this but it's about Ajax messing up wice_grid and I have not used Ajax anywhere in my application at all.


I'm assuming this has something to do with some obscure problem in my own application. Some piece of JavaScript that's overriding the wice_grid filtering functionality silently? However I'm not sure and wanted to run this by people here, just in case I'm missing something obvious or there are questions to ask that I'm not thinking of properly.

leikind commented 9 years ago

Weird.

Could you try to comment off your application JS code?

Could you add console.log(...) statements in wice_grid_init.js.coffee and see if any of these methods get executed at all?

HazelGrant commented 9 years ago

That was exactly what I needed to do. Thank you.

This had to do with the 'gon' gem. I have a javascript file where I point towards a gon variable which only exists on one page/within one controller action, but the file was available to the whole application. This meant there was a an undefined JavaScript variable trying to hang out all over the place, resulting in 'gon is not defined' errors on every page except the one where my gon variable was defined. So I made it so that script is only available in the one place, and the tables started filtering correctly. So I was just failing to pay close attention, although I'm not exactly sure why that interfered with filtering. Fixing that removed the problem.

Thanks again for your insight.