您的位置:首页 > Web前端 > JQuery

jquery datatable 配合 rails 进行后台分页

2013-11-19 01:00 288 查看
1 . 在datatables 中加入

"sPaginationType" : "full_numbers" ,

"bServerSide": true,

2个参数。"bServerSide": true, 必须要加。否则不会传递相关参数给后台

2. 传入后台的相关 参数 和 后台需要传出的参数 可以参考 api 文档 http://datatables.net/usage/server-side
int iDisplayStart Display start point in the current data set.
intiDisplayLengthNumber of records that the table can display in the current draw. It is expected that the number of records returned will be equal to this number, unless the server has fewer records to return.
特别是这2个参数。用于后台进行分页处理

3. rails 后台进行 分页的逻辑处理

def index
idisplaystart   = params[:iDisplayStart]
idisplaylength  = params[:iDisplayLength]
secho = params[:sEcho]

itotalrecords =  GisRoadLink.where("activate  = ?",params[:activate]).count()
items = GisRoadLink.where("activate  = ?",params[:activate]).order("id asc").limit(idisplaylength).offset(idisplaystart)
for item in items do
item_array = []
item_array << item.id
item_array << item.no
....
end
json_hash.store("aaData",items_array)
json_hash.store("iTotalRecords",itotalrecords)
json_hash.store("iTotalDisplayRecords",itotalrecords)
json_hash.store("sEcho",secho)
render json: json_hash
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: