Made by Nathan

programming and projects

Jqgrid on Spree

| Comments

Been a fan of jqgrid for quite some time, but wasn’t looking forward to the struggle of getting it to work with Rails.

Thankfully, someones already done it for me: http://www.2dconcept.com/jquery-grid-rails-plugin

It did take a little while to debug some things that were going wrong, though. Firebug was giving me the error: $.jgrid.formatter is undefined. After some digging around, I realized that no jqgrid locale files were being loaded.

By default, Spree has its i18n locale set to “en-US”. 2dcJqgrid has a fancy method that sets the jqgrid locale to the same locale as your Rails app, but unfortunately that breaks down for any ‘en-**’ locales, because jqgrid only has the one ‘en’ locale file in its ‘i18n’ directory.

The simple fix is to change the file ‘2dc_jqgrid.rb’ (starting from line 11), from this:

def jqgrid_javascripts
    locale = I18n.locale rescue :en
    js = ''
    ...

to this:

def jqgrid_javascripts
    locale = I18n.locale rescue :en
    locale = :en if locale.to_s.start_with?("en")
    js = ''
    ...

« Last.fm Player - Project Videos obscure jqGrid API notes »

Comments