0

我在rails中使用jqgrid在我的网络中显示数据,我想根据用户正在浏览的页面来决定显示哪些数据这是代码

显示.html.erb

<%=raw jqgrid("people_list", "people", "/people", 
  [ { :field => "pid", :label => "pid" ,:editable => true},
    { :field => "name", :label => "name" ,:editable => true},
    { :field => "gender", :label => "gender" ,:editable => true},
    { :field => "birthday", :label => "birthday" ,:editable => true}
  ] ,
  {:autowidth=>true,:add => true,:edit => true,:delete => true,:view => true,:edit_url => post_data_people_url,:sortable_rows => 'true'
  }  
)%>

people_controller.rb

def index
  index_columns ||= [:pid,:name,:gender,:birthday,:school]
  current_page = params[:page] ? params[:page].to_i : 1
  rows_per_page = params[:rows] ? params[:rows].to_i : 10

  conditions={:page => current_page, :per_page => rows_per_page}
  conditions[:order] = params["sidx"] + " " + params["sord"] unless (params[:sidx].blank? || params[:sord].blank?)

  if params[:_search] == "true"
    conditions[:conditions]=filter_by_conditions(index_columns)
  end

  @temp = Person.limit(0).all
  KlassesPeople.where(:klass_id => 1).each do |stu|########
    @temp.concat( Person.where(:id => stu.person_id) )
  end
  @people = @temp.paginate(conditions)
  total_entries=@people.total_entries

  respond_with(@people) do |format|
    format.html
    format.json { render :json => @people.to_jqgrid_json(index_columns, current_page, rows_per_page, total_entries)}  
  end
end

我想将 jqgrid 中的 klass id 的值传递给控制器​​,以确定带有“########”的行中的 klass_id 的值

任何想法?

4

1 回答 1

0

我不知道如何为您格式化代码,但是postData每次 jqGrid 获取数据时,您都可以使用该参数将值传递给您的控制器。

postData: { KeyName: KeyValue },

如果您需要动态设置此值,您可以通过以下方式设置它:

$('#gridName').jqGrid('setGridParam', { postData: { KeyName: KeyValue });
于 2013-05-07T11:50:23.233 回答