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

Custom order and no filter without an attribute? #187

Closed kosh-jelly closed 9 years ago

kosh-jelly commented 9 years ago

I've implemented wice_grid column that does not use data directly from the database and it has a custom_order with pure sql. It looks like I have to add a db attribute in order to use that custom filter. Is that correct?

@seed_url_grid = initialize_grid(SeedUrl,
  include: [:error_domains],
  custom_order: {
    'error_domains.available' => "( 
        SELECT COUNT(*) FROM error_domains  
        WHERE error_domains.seed_url_id = seed_urls.id 
          AND error_domains.available = 1 
          AND (error_domains.moz_da BETWEEN 15 AND 100) 
    )" 
  })

And in the view:

g.column name: 'Available DA Domains', attribute: 'available', model: 'ErrorDomain', filter: false do |seed|
    seed.available_da_domains   # This is a model method, not a db attribute
  end

This isn't mission critical by any means, but it seems silly to require using a random db attribute when that db attribute is not relevant to the custom filter. Any way around this?

If this is a bug, and anyone could point me in the right direction for how we might fix it, I'm happy to give it a hack.

leikind commented 9 years ago

Yes, a db column is currently a requirement if you want to use ordering. It is not a bug, even though does seem a bit silly. By design the plugin relies on db columns to figure out the type of the filter, etc

kosh-jelly commented 9 years ago

Ah ok. Thanks. Would it be possible to not raise an error if :filter => false?

I realize this isn't a priority, but the thought occured to me to I figured I'd share it :) (btw I'm a huge fan of this project! Thanks for creating it)

leikind commented 9 years ago

yes, I think so. The problem is I do not have time for WiceGrid these days.