(first posted: Jan 09, 2010)
(632 Reads)
keywords: jqgrid jquery
Permalink
Gridify - A Ruby wrapper and Rails plugin for jqGrid
Gridify is a Ruby wrapper and Rails plugin for jqGrid.
jqGrid is a rich featured data grid built with the jQuery javascript library. www.trirand.com/jqgridwiki/doku.php
Gridify defines a simplified, more consistent API for jqGrid rather than directly emulate the jqGrid api and options in Ruby.
Gridify tries to respect the MVC (model-view-controller) architecture of your application. This is challenging because grid features span all three areas: it’s clearly part of the "view" as it mostly resides in the browser; columns in the table often directly map to columns in the model (database); and grid’s ajax requests are handled by controllers. Gridfy gives you some flexibility in managing grids within MVC.
Example
Lets say we have an ActiveRecord model "Note" which we want to display in a grid.
In app/models/note.rb,
class Note < ActiveRecord::Base
gridify
end
In the NotesController,
def index
if request.xhr?
records = Note.find_for_grid :grid, params
render :xml => Note.grid.encode_records(records)
else
@grid = Note.grid
end
end
In the app/views/notes/index.html.erb,
<%= @grid %>
<h1>Notes Grid<h1>
<table id="notes_grid"></table>
<div id="notes_grid_pager"></div>
In this example, gridify creates a default grid named "grid" for the Notes model. In the controller, the #index html action supplies the @grid object used by the view; the #index xml action responds to request params with the encoded data. In the view, @grid.to_s generates the javascript code needed for the grid, which populates the table and pager div.
The project source code and more documentation is on github at
http://github.com/linoj/gridify
hi, if you want to use will_paginate then dont use the #find_for_grid method. Instead you'll need to inerpret the params passed by jqgrid in your controller.
But I'm not sure why you'd want to use will_paginate. find_for_grid does pagination, and with jqgrid you dont use the will_paginate view helpers.




Gridify - A Ruby wrapper and Rails plugin for jqGrid
Posted by: guest on January 19, 2010 06:16 AM#