Rails - jqGrid无法使用will_paginate / array进行排序和搜索

时间:2013-05-17 09:29:56

标签: ruby-on-rails ruby-on-rails-3 jqgrid will-paginate

我使用jqGrid和will_paginate制作表格。 这是我在控制器中的代码

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

  @people = Person.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中正确排序和搜索数据。 但是,在我将其修改为

之后
  @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

数据仍然可以在jqGrid中显示,但不能排序和搜索 我在我的控制器中添加了'require_paginate / array'

任何想法?

1 个答案:

答案 0 :(得分:0)

我在rails 4.0上使用ruby上传了jqgrid服务器端搜索和CRUD操作

找到以下链接 -

https://github.com/Rameshwar007/jqgrid_rails_4_sample

如果您有任何疑问,请告诉我。