Skip to content
bigfleet edited this page Sep 12, 2010 · 8 revisions

Binary filtration:

For value fields

For cases when the model has a value attribute for which a value isn’t required.


data_table(:artists) do |table|
  table.filter_spec do |f|
    f.element(:homepage) do |e|
      e.default "All"
      e.option  "with homepage", :when => :not_nil
      e.option  "without homepage", :when => :nil
    end
  end
end

For boolean fields

For cases when the model has a boolean attribute.


data_table(:artists) do |table|
  table.filter_spec do |f|
    f.element(:taper_friendly) do |e|
      e.default "All"
      e.option  "allow taping", :when => true
      e.option  "do not allow taping", :when => false
    end
  end
end

Has/has not

When a model has_many of another model, the parent table has no reference to the child. data_table ought to be smart enough to team with the finder to allow filtration on it.


data_table(:rentals) do |table|
  table.filter_spec do |f|
    f.element(:rating) do |e|
      e.default "All"
      e.option  "Rated", :when => true
      e.option  "Unrated", :when => false
    end
  end
end

Time filtration:

Back from, forward to

Filter based on some field’s time value, with configurable distances. (This should also work into the future.)


data_table(:live_shows) do |table|
  table.filter_spec do |f|
    f.element(:show_date) do |e|
      e.option  "Last 6 months", :since => 6.months.ago
      e.default "This Year", :since => 1.year.ago
      e.option "Last 5 years", :since => 5.years.ago
    end
  end
end

Time span

This should include an “open ended” option on the current side, and allow for filtering on part of a date, like the year


data_table(:live_shows) do |table|
  table.filter_spec do |f|
    f.element(:show_date) do |e|
      e.option  "2000's", :when => {:year => {:between => [2000, :now]}}
      e.option  "1990's", :when => {:year => {:between => [1990, 1999]}}
      e.option  "1980's", :when => {:year => {:between => [1980, 1989]}}
      e.option  "1970's", :when => {:year => {:between => [1970, 1979]}}
    end
  end
end

Count filtration:

On an attribute

Filter on some count figure, whether counter_cache’d within Rails, or virtually produced by the RDBMS


data_table(:artists) do |table|
  table.filter_spec do |f|
    f.element(:album_count) do |e|
      e.default  "1-10", :between => [1, 10]
      e.option  "11-25", :between => [11, 25]
      e.option  "25+", :more_than => [25]
    end
  end
end

On a summation or average

We may want to filter on some calculation over some subcollection


data_table(:salesmen) do |table|
  table.filter_spec do |f|
    f.element(:sales) do |e|
      e.default  "<100k", :sum => {:order_total => {:between => [1, 100000]}}
      e.option  "100-250k", :sum => {:order_total => {:between => [100000, 250000]}}
      e.option  "25+", :sum => {:order_total => { :more_than => [250000] }}
    end    
  end
end

Don’t Forget

  • Tags are often on polymorphic taggables— a tag listing should be able to filter based on that type. Might be able to use details of popular tagging implementations.
  • Search may also result in similar polymorphic results. Might be able to use details of popular search plugins (sphinx, solr).
Clone this wiki locally