Rails WiceGrid with multiples attributes in the same column

633 views Asked by At

My project has 2 columns for the table user, "first_name"" and "last_name" and I want to show them in just 1 column and with 1 field to filter it (Full Name). I have something like that:

g.column name: 'First Name', attribute: 'first_name' do |user|
    user.first_name
end

g.column name: 'Last Name', attribute: 'last_name' do |user|
    user.last_name
end 

I want to do something like that:

g.column name: 'Full Name', filter: proc{ |q| where("first_name LIKE :query OR last_name LIKE :query", query: "%#{q}%") } do |user|
    user.first_name + ' ' + user.first_name
end

Is that possible?

If yes, what should I do to be able to custom the filters like that?

Thank you.

2

There are 2 answers

0
maurymmarques On

I think that isn't possible yet.

The createor of WiceGrid said:

unfortunately this is not possible, but there is a simple workaround which I implemented multiple times: I create one more column name and it gets populated in before_save

Check all comments here:

https://github.com/leikind/wice_grid/issues/225

1
Bekka Djahid On
g.column name: 'links' do |product|
  buffer = link_to "Show", show_product_path
  buffer += ' '
  buffer = link_to "Edit", edit_product_path
  raw buffer
end