I have a sorting problem with using the gem wice_grid. I have a table/grid for sent messages and it contains various columns. In the messages controller:
def index
@messages_grid = initialize_grid( Message,
per_page: 40,
order: 'messages.created_at',
order_direction: 'desc' )
end
The gem offers a sorting functionality and that works for most of the columns. However for the columns that involve an associated table (User), sorting (and filtering) fail. If I click to sort on these columns, I get an error, which refers to the line in the view page: <%= grid(@messages_grid, show_filters: :when_filtered, html: {class: 'my-grid'}) do |g|
:
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "users"
LINE 1: ...ECT "messages".* FROM "messages" ORDER BY "users
^
: SELECT "messages".* FROM "messages" ORDER BY "users"."username" asc LIMIT 40 OFFSET 0
The column of concern here is as follows in my view page:
g.column name: 'Sender', model: 'User', attribute: 'username', auto_reload: true, html: {id: 'grid-cells'} do |message|
unless message.sender.nil?
link_to(message.sender.username, user_path(message.sender))
end
end
Does anyone understand why sorting when associated tables are involved is going wrong? I'm using wice_grid 3.5.0, Rails 4.2.3 and the console displays no javascript errors.
Use :include in :initialize_grid to include associated tables. http://wicegrid.herokuapp.com/joining_tables