# Rails/YUI-Grid Question

**URL:** <https://www.ruby-forum.com/t/rails-yui-grid-question/74149>\
**Category:** Rails\
**Created:** [October 31, 2006, 7:43am UTC](https://www.ruby-forum.com/t/rails-yui-grid-question/74149 "2006-10-31T07:43:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmarmer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@rmarmer1](https://www.ruby-forum.com/u/rmarmer1)\
**Post date:** [October 31, 2006, 7:43am UTC](https://www.ruby-forum.com/t/rails-yui-grid-question/74149/1 "2006-10-31T07:43:16Z")

</div>

Hello. I’m looking at using the YUI grid component in a rails app.

Typically I’d use an html table object, do a db call along the lines of

@aCollection = AModel.find(:all)

& use a partial to loop thru the collection & populate the rows…

How would you populate the YUI grid in rails?

Would RJS &/or the rails “to\_xml” method be part of a reasonable  
approach here & if so, what would that look like?

Thanks!

---

<div class="post-metadata">

**Author:** ![rmarmer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@rmarmer1](https://www.ruby-forum.com/u/rmarmer1)\
**Post date:** [October 31, 2006, 3:03pm UTC](https://www.ruby-forum.com/t/rails-yui-grid-question/74149/2 "2006-10-31T15:03:43Z")

</div>

Oh and here is a starting point:

[http://wiki.rubyonrails.org/rails/pages/HowToWorkWithTheYUI](http://wiki.rubyonrails.org/rails/pages/HowToWorkWithTheYUI)

But I don’t see how he handles using XHR with YUI.

---

<div class="post-metadata">

**Author:** ![rmarmer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@rmarmer1](https://www.ruby-forum.com/u/rmarmer1)\
**Post date:** [October 31, 2006, 2:58pm UTC](https://www.ruby-forum.com/t/rails-yui-grid-question/74149/3 "2006-10-31T14:58:11Z")

</div>

It’s going to depend more on how YUI works than rails. Honestly, I  
haven’t had much expierence with YUI, but typically, YUI controls like  
for you to render the entire HTML just like you normally do. After that  
apply the javascript to your page to turn it into a grid. YUI  
philosophy is more of the unobtrusive javascript which the rails guys  
typically don’t do.

Now I’m not sure what it does for fetching data asynchronously. I don’t  
think RJS would be that helpful since it’s built on top of the Prototype  
library to create all the javascript. If you use RJS you’ll be  
combining Prototype and YUI together. While it could work you’ll  
probably run into strange issues combining them. You’ll have to be  
careful if you take that approach. Personally I like to avoid weird  
issues that no one will be able to help me with so I’d try to stear  
clear of mixing protoype and YUI. That also means things like  
remote\_link\_to might be off limits as well because that all generates  
Prototype code as well.

Charlie

---

<div class="post-metadata">

**Author:** ![rmarmer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@rmarmer1](https://www.ruby-forum.com/u/rmarmer1)\
**Post date:** [November 1, 2006, 3:25am UTC](https://www.ruby-forum.com/t/rails-yui-grid-question/74149/4 "2006-11-01T03:25:24Z")

</div>

Charlie H. wrote:

> It’s going to depend more on how YUI works than rails. Honestly, I  
> haven’t had much expierence with YUI, but typically, YUI controls like  
> for you to render the entire HTML just like you normally do. After that  
> apply the javascript to your page to turn it into a grid. YUI  
> philosophy is more of the unobtrusive javascript which the rails guys  
> typically don’t do.
> 
> Now I’m not sure what it does for fetching data asynchronously. I don’t  
> think RJS would be that helpful since it’s built on top of the Prototype  
> library to create all the javascript. If you use RJS you’ll be  
> combining Prototype and YUI together. While it could work you’ll  
> probably run into strange issues combining them. You’ll have to be  
> careful if you take that approach. Personally I like to avoid weird  
> issues that no one will be able to help me with so I’d try to stear  
> clear of mixing protoype and YUI. That also means things like  
> remote\_link\_to might be off limits as well because that all generates  
> Prototype code as well.
> 
> Charlie

Hey Charlie,

Thanks for your comments!

Seems I was confused… I was actually referring to the yui-ext grid  
component by Jack Slocum [http://www.jackslocum.com/yui/index.php](http://www.jackslocum.com/yui/index.php).

The initial problem for me is that I don’t understand how to load the  
grid once I have the query reults in a rails collection.

The grid api seems to provide several methods for loading data,  
including xml & json. On learning that I thought of the rails to\_xml &  
to\_json methods, but I’m still left with the question of how the data  
gets passed into the grid…

As for adding rjs to the mix… your point is a good one!

I will continue to look into this & if/when I get a grip on it I’ll post  
something on it.

Thanks again.

Randy
