Ruby on Rails Data Grid Control 14

Posted by sbecker Sun, 10 Jul 2005 11:38:00 GMT

As far as I can tell, Ruby on Rails doesn’t have a built in control for displaying tabular data in a grid. Not a rich one anyway, with paging/sorting/filtering capability built-in. I plan on attempting to create one. I’m actually almost there. I’m doing this instead of getting my actual projects done. :)

All parameters should have defaults to do the standard thing, with ability to further customize if so desired. Convention over configuration and all that. It should be able to do sorting/paging on columns from associated tables as well. Here’s the proposed syntax for how this might be called in a controller:

a simple example
class AgreementsController < ApplicationController

  def list_simple
    grid_view(Agreement,
      :columns => ['title', 'active', 'amount', 'frequency']
    )
  end

end

a more complex example:

class AgreementsController < ApplicationController

  def list_complex
    grid_view(
      Agreement,
      :columns => [
        "Status",
        "Company Name" => {
          :dbcolumn => "company_name",
          :filter => true
        },
        "Category" => {
          :dbcolumn => "agreement.category_id",
          :filter => true,
          :filter_type => :select,
          :filter_options => Category.find_all.collect {|c| [ c.name, c.id ] }
        },
        "Active" => {
          :dbcolumn => "agreement.active",
          :filter => true,
          :filter_type => :select,
          :filter_options => [["Yes", 1], ["No", 0]]
        }
      ],
      :joins => ["LEFT OUTER JOIN categories ON agreements.category_id = categories.id",
                 "LEFT OUTER JOIN companies ON agreements.company_id = company.id"]
      :alias_columns => [["companies.name", "company_name"],["categories.name", "category_name"]],
      :order_by => "category_name, products.name",
      :per_page => 25
    )
  end

end

The grid_view method will be at the application level, so you can call it from any controller. The presentation (view) will live in one /shared/_grid_view.rhtml partial file and be 100% customizable. And because of that, it doesn’t even have to be a table or look like a grid! The MVC pattern of rails allows this, and would make this far superior and easier to customize than say – the ASP.NET data grid control, in my opinion. Here’s one possible way such a beast might look like:

Comments

Leave a response

  1. Avatar
    vegeta.z@gmail.com Tue, 21 Feb 2006 04:23:39 GMT
    any progress? because i am really interested on this component, i would like to help you finishing it. contact me plz.
  2. Avatar
    omer Fri, 21 Jul 2006 11:31:04 GMT

    still no progress? :(

  3. Avatar
    Marco Oechslin Tue, 15 Aug 2006 09:10:42 GMT

    Is there any source code available? I would like to use a datagrid with it’s data stored in a mysql database for my project. I need a possibility to add rows and sort colums and I need a Cell editing capability. First I googled through ajax solutions because I wanted editable cells by mouseclick, but I couldn’t find a simple non commercial framework.

  4. Avatar
    dak AT itracker DOT com Sat, 03 Feb 2007 21:16:41 GMT

    I would use your Datagrid MANY times if it was going. I’ve conerting my efforts from ASP and was using the DevExpress datagrid. How about letting me know how it’s going? dak AT itracker DOT com

  5. Avatar
    Stanly Tue, 10 Apr 2007 12:23:06 GMT

    Any progress in the project…

  6. Avatar
    Nate Thu, 14 Jun 2007 21:23:42 GMT

    I’m interested in this project as well. Any chance you will pick it up almost two years later?

  7. Avatar
    yatender Thu, 28 Jun 2007 07:40:46 GMT

    i would love if such a datagrid is availaible on rails

  8. Avatar
    Benni Fri, 13 Jul 2007 22:14:29 GMT

    Any news on the Rails datagrid?

  9. Avatar
    Adi Wed, 12 Dec 2007 21:19:42 GMT

    Any progress on this grid?

  10. Avatar
    mmorpg Wed, 05 Mar 2008 22:06:21 GMT

    Creating tabular data in a grid form is no easy task…I read some other ruby rails blogs and they are struggling with it.

  11. Avatar
    mmorpg Wed, 05 Mar 2008 22:07:21 GMT

    repost?

  12. Avatar
    https://redmine.wice.eu/wiki/wice-grid Tue, 18 Nov 2008 09:40:59 GMT
  13. Avatar
    Sekhar Wed, 07 Jan 2009 19:36:53 GMT

    man that was a long time ago. maybe this dude died or something…and where did he get that screenshot? photoshop?

  14. Avatar
    Sekhar Wed, 07 Jan 2009 19:37:11 GMT

    man that was a long time ago. maybe this dude died or something…and where did he get that screen shot? photo shop?

Comments