github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

flaviogranero / filter_table

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 6
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

An easy way to add links with default filters for HTML tables in your Rails app. — Read more

  cancel

http://flaviogranero.com

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

fixed problem with filter value with a composed word, added tests 
flaviogranero (author)
Sat Feb 28 10:54:15 -0800 2009
commit  999cbdfff58ebd5ed8cebafa5dd0d6284d350954
tree    574ba2616c9a0e9677761c59cc4e97846a079058
parent  cb8e07e6cc922b346ebe89da2c7b676a3c5064f5
filter_table /
name age
history
message
file .gitignore Thu Feb 26 11:10:36 -0800 2009 first commit [flaviogranero]
file MIT-LICENSE Thu Feb 26 11:10:36 -0800 2009 first commit [flaviogranero]
file README.textile Loading commit data...
file Rakefile
file TODO.textile
file init.rb
directory lib/
directory rails/ Thu Feb 26 11:10:36 -0800 2009 first commit [flaviogranero]
directory test/
README.textile

Filter Table

An easy way to include links with default filters for HTML tables in your Rails app.

Install

script/plugin install git://github.com/flaviogranero/filter_table.git

Controller


  class CarsController < ApplicationController
    filter_attributes :status

    def index
      @cars = Car.paginate :page => params[:page], :conditions => filter_conditions
    end
  end

The filter_attributes defines a filter_conditions method that gets called in your action.
This method returns the query conditions based in params of request.

View


  <h1>Cars</h1>
  <div>
    <h2>Filters</h2>
    <%= filter_links_for :status, :values => {'Normal' => 0, 'Broken' => 1, 'Running away' => 2} %>
  </div>
  <table>
    <tr>
      <th>Name</th>
      <th>Status</th>
      <th>Category</th>
    </tr>
    <% @cars.each do |car| %>
      <tr>
        <td><%=h car.name %></td>
        <td><%= car.status %></td>
        <td><%= car.category %></td>
      </tr>
    <% end %>
  </table>

The filter_links_for generates a html list containing a link for each filter value. Also, is allowed the param :title to informe a display name for the list, and the list item active has a css class “filter_active”, but you can change this using the :active_class param.
The param :values can receive an array of values or, if you want to create a list based on distinct values existent in database, use the keywork :auto. See the example below, with filter links for category attribute:


  <h1>Cars</h1>
  <div>
    <h2>Filters</h2>
    <%= filter_links_for :status, :values => {'Normal' => 0, 'Broken' => 1, 'Running away' => 2} %>
    <%= filter_links_for :category, :values => :auto, :model => 'Car' %>
  </div>
  <table>
    <tr>
      <th>Name</th>
      <th>Status</th>
      <th>Category</th>
    </tr>
    <% @cars.each do |car| %>
      <tr>
        <td><%=h car.name %></td>
        <td><%= car.status %></td>
        <td><%= car.category %></td>
      </tr>
    <% end %>
  </table>

At this case, a :model param is required and a query will be created to get all the values.

Version 0.1
-————

February 26, 2009

Author
-——

Flávio Granero – http://flaviogranero.com

Copyright © 2009 Flávio Granero, released under the MIT license

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server