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. |
int | iDisplayLength | Number 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. |
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