我使用 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 'will_paginate/array'
任何想法?