I’m trying to incorporate Rico’s LiveGrid functionality into a Rails
page.
So far I’ve been able to download rico.js into my public/javascripts
folder and load it into the section of my application.rhtml using
javascript_include_tag. Following Rico’s tutorial at http://openrico.org/docs/RicoLiveGrid.pdf, I added the option
onload=“javascript:bodyOnLoad()” to my in application.rhtml.
Moving to the next step in the tutorial, I gave my existing Borrowers
table an id=“data_grid_content” and created a header row table with
id=“data_grid_header”.
Now to the problem step, the JavaScript function to actually create the
grid. The tutorial uses JSP to load its table, and I want to use Rails -
the instance variable @borrowers holds the proper page of data in the
pre-Rico pagination setup. The code in the tutorial is:
I tried substituting @borrowers for getMovieTableContent.do (both with
and without the single quote marks). The result in either case is no
response - the existing page (with the added header row) shows up as
before. No grid appears. There is no error or flash message.
Can anyone help with this? I know it’s just a matter of what/how to
substitute and maybe also some layout issue with needing extra
or
sections. Since prototype.js is already part of Rails and
rico.js uses Prototype, I thought it should be easy to incorporate Rico
widgets into a Rails app. But I haven't found any Rails LiveGrid
examples out there.
Just a stab here (I’m not positive), but it would seem to me that you
would need to supply a Rails action name in place of
‘getMovieTableContent.do’ that would output some sort of data
structure. I don’t know what that would be, but I’m sure the
tutorial/javascript file can tell you.
Sorry for not catching the PDF link before; it looks like you need to
create a Rails action that outputs an HTML table. Rico then appears
to take the HTML table and turn it into the grid. The tutorial shows
how you need to format the output if you’re using AJAX.
Yes, I have an existing borrowers/list.rhtml page that displays a page
of Borrowers data, which I previously created based on the depot app in
AWDwR. To generate that page, the borrowers_controller.rb has a method
def list @borrower_pages, @borrowers = paginate :borrowers, :per_page => 8,
:order_by => ‘LastName, FirstName’
end
This appears to collect a page of data into the @borrowers variable. So
do I need to refactor or rename this def somehow? How would I refer to a
controller method in the example instead of in-line js code?
If I’m reading it correctly, getMovieTableContent.do is merely
pointing to a URL for a JSP. So, in theory you should be able to put
‘list’ (or something like that) and get your desired output.
Of course, this is all in theory. I’m not sure if they have some
special wiring with JSPs or not. I would suggest creating a
plain-jane HTML file and plugging in a simple table in there to test
that theory (i.e., create ‘table.html’ and replace
getMovieTableContent.do with ‘table.html’).
I’m downloading Rico right now…if that doesn’t solve it I’ll play
around with it and see if I can give you a solution.
I tried replacing ‘getMovieTableContent.do’ with ‘table.html’ and
replacing my Rails table-generating code with the expanded table that it
turns into in the View / Page Source. It didn’t make any difference. I
still get the normal rendering of the table. (I put this in a
borrowers/listRico.rhtml template file and pointed the list action
there. I know it got there because I changed the header row only in that
template and that part rendered properly, just no liveGrid showed up.)
Now I suspect I might have to do something in the .css file, or maybe I
left out some other crucial piece. The sample site has more and
different code than the tutorial, but the sample site includes other
widgets on the same page as well.
Thanks for checking out Rico! I came across a couple of other attempts
to do this in the forum but no one actually said they got it.
I found an example of incorporating Rico LiveGrid into a rails app.
Well, it’s not exactly incorporating it; it’s a standalone example, so
I have to figure out how to divide up the js parts to be more generic.
That is, I don’t want to reference “Borrowers” in my application.rb,
which is where the <body onload= … element is.
Anyway, here’s the reference if you or anyone else want to play with it:
Shauna
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.