leikind / wice_grid

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

WiceGrid with multiples attributes in the same column #225

Closed maurymmarques closed 9 years ago

maurymmarques commented 9 years ago

My project has 2 columns for the table users, "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 (or maybe something simpler):

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.

leikind commented 9 years ago

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

maurymmarques commented 9 years ago

All right. I do not think it's the best solution though. I also thought that maybe it was possible to do something that would work in the controller side.

Something like:

@users_grid = initialize_grid(
    User.where('first_name LIKE ? OR last_name LIKE ?', "%#{params[:grid][:f][:first_name]}%", "%#{params[:grid][:f][:last_name]}%")
)

But itsn't working yet.

Thank you.

leikind commented 9 years ago

hm.. the first argument can be an ActiveRelation, so theoretically this should work

maurymmarques commented 9 years ago

I will keep trying, if I get it I will write it here. Another question... Is there a way to change the date format for the datepicker? http://awesomescreenshot.com/0854ytv050 I would like to define something like "09/06/2015" Thank you very much, Yuri.

maurymmarques commented 9 years ago

Oh, I got it, It's a constant 'DATE_FORMAT_JQUERY'. I'm sorry.

leikind commented 9 years ago

right, was just about to post this link https://github.com/leikind/wice_grid/blob/rails3/lib/generators/wice_grid/templates/wice_grid_config.rb#L133