Forum


17:03

17/02/2009

Hi all,
I'm trying to use jqgrid in ruby on rails to display a table, but I can't get it to display the data. If i go to http://127.0.0.1:3000/planets it only shows me the table heading.
If I go to http://127.0.0.1:3000/planets/grid_data however it does show the correct information (tho it complains "This XML file does not appear to have any style information associated with it. The document tree is shown below." but I think that is normal).
I've tried various things but I just can't get it to work 🙁
Here's what I think are the relevant bits of my source files. I cut out bits where I'm pretty sure that they don't matter but put [...] to denote where I made cuts.
app/views/planets:
<%= jquery_grid :sample, {:url => grid_data_planet_url } %> doesn't
#using this doesnt work either: <%= jquery_grid :sample, {:url => "http://127.0.0.1:3000/planets/grid_data" } %>
<center>
<div style="background :black; color:white; width:818px;">Planets - Uni40.org</div>
<%= jquery_grid_table %>
<%= jquery_grid_pager %>
</center>
<br />
app/controllers/planets_controller.rb:
[...]
def grid_data
params[:sidx]=:id
params[:sord]="asc"
params[:rows]=20
@planets = Planet.all(:order => "#{params[:sidx]} #{params[:sord]}")
respond_to do |format|
format.xml { render :partial => 'grid_data.xml.builder', :layout => false }
end
end
[...]
config/routes.rb:
ActionController::Routing::Routes.draw do |map|
map.resources :planets, :collection => {:grid_data => :get}
map.resources :planets
[...]
app/views/layouts/application.html.erb:
<html>
<head>
<title>Railpot in Ajax</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<%= javascript_include_tag 'jquery' %>
<%= include_jquery_grid_javascript %>
<%= include_jquery_grid_css %>
</head>
<body>
<%= yield %>
</body>
</html>
</pre>
app/views/planets/_grid_data.xml.builder:
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
xml.rows do
xml.page params[:page]
xml.total_pages(@planets.size.to_i / params[:rows].to_i)
xml.records{@planets.size}
@planets.each do |u|
xml.row :id => u.id do
xml.cell u.universe_id
xml.cell u.player_name
xml.cell u.galaxy_no
xml.cell u.system_no
xml.cell u.planet_no
end
end
end
config/jquery_grid/sample.yml:
---
:before: var lastsel2;
:params:
:datatype: xml
:mtype: GET
:colNames:
- universe_id
- player_name
- galaxy_no
- system_no
- planet_no
:colModel:
- :width: 130
:index: universe_id
:name: universe_id
:editable: true
- :width: 130
:index: player_name
:name: player_name
:editable: true
- :width: 80
:index: galaxy_no
:name: galaxy_no
:editable: false
- :width: 80
:index: system_no
:name: system_no
:editable: false
- :width: 80
:index: planet_no
:name: planet_no
:editable: false
:pager: $('#<grid_name>_pager')
:function_onSelectRow: "(id)
if(id && id!==lastsel2) {
$('#<grid_name>').restoreRow(lastsel2);
$('#<grid_name>').editRow(id,true);
lastsel2=id;
}"
:sortname: first_name
:sortorder: desc
:rowNum: 10
:imgpath: /stylesheets/jqGrid-themes/basic/images
What am I missing?
Cheers, Steffen
05:08

17/02/2009

05:35

Moderators
30/10/2007

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
05:51

17/02/2009

That's what I worked off actually 🙂 Should've probably mentioned that..
Basically I just copied that code, replacing bits where relevant with my own object name (ie planets instead of people). Other than that the differences are me trying to get it to work
Is there any particular bit that I should be looking at? I compared everything probably a dozen times by now but I just seem to be unable to find it 🙁
Most Users Ever Online: 715
Currently Online:
34 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66