Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Can't get jqgrid on rails to display data
16/02/2009
17:03
Avatar
steffen780
Manchester
Member
Members
Forum Posts: 4
Member Since:
17/02/2009
sp_UserOfflineSmall Offline

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

17/02/2009
05:08
Avatar
steffen780
Manchester
Member
Members
Forum Posts: 4
Member Since:
17/02/2009
sp_UserOfflineSmall Offline

I found a mistake I made in sample.yml, :sortname is now set to player_name but still the same result 🙁

17/02/2009
05:35
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Could you please look here:

http://www.rubyrailways.com/ad.....5-minutes/

Regards

Tony

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.

17/02/2009
05:51
Avatar
steffen780
Manchester
Member
Members
Forum Posts: 4
Member Since:
17/02/2009
sp_UserOfflineSmall Offline

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 Innocent

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 🙁

17/02/2009
05:53
Avatar
steffen780
Manchester
Member
Members
Forum Posts: 4
Member Since:
17/02/2009
sp_UserOfflineSmall Offline

steffen780 said:

app/views/planets:

<%= jquery_grid :sample, {:url => grid_data_planet_url } %> doesn't


The file name is of course: app/views/planets/index.html.erb

And the first line should read: <%= jquery_grid :sample, {:url => grid_data_planets_url } %>

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information