views:

184

answers:

1

Has someone a working example with sample code. I integrated the plugin as described in http://github.com/linoj/gridify. I see the grid header but no data. i have verified that I am sending data from the controller. Anyone has answers or a complete sample that is download-able? thanks sukanta

A: 

It is really picky on the correct order and spelling of everything. I had that a lot when setting up my tables.

controller:

def index
statics = Static.find(:all) do
  if params[:_search] == "true"
    name    =~ "%#{params[:name]}%" if params[:name].present?
    content  =~ "%#{params[:content]}%" if params[:content].present?                      
  end
  paginate :page => params[:page], :per_page => params[:rows]      
  order_by "#{params[:sidx]} #{params[:sord]}"
end

respond_to do |format|
  format.html
  format.json { render :json => statics.to_jqgrid_json([:id,:name,:content], params[:page], params[:rows], statics.total_entries) }
end
end

index.html.erb:

<%= jqgrid("Static Pages", "statics", "/admin/statics",
[
    { :field => "id", :label => "ID", :width => 35, :resizable => false },
    { :field => "name", :label => "Name", :width => 100, :editable => true },
    { :field => "content", :label => "Content", :width => 800, :editable => true, :edittype => "textarea", :editoptions => { :rows => 20, :cols => 60 } }
], { :add => true, :edit => true, :inline_edit => false, :delete => true, :edit_url => "/admin/statics/post_data" }
) %>

This works for me. Common problems I had were: 1. misspelling of field, 2. Forgot one occurrence of model, 3. Accidentally pluralized where I shouldn't (and the other way round), 4. Incorrect order of variables in the format.json line.

I know it's a late reply. Hope it still helps.

val_to_many