EasyUI 分页其实不复杂,用RoR 搞定很简单。
$('#td_grid').datagrid({
url:'/data/get_grid_data',
pagination:true,
pageSize:20,
striped:true,
== 关键是如何返回 , 一个是total, 一个是json数据:
def get_grid_data
page = params['page']
rows = params['rows']
#cond_str = bla.
offset = (page.to_i-1)*rows.to_i
total = Db.find_by_sql("select count(*) from my_table #{cond_str};")[0].count
user = Db.find_by_sql("select * from my_table #{cond_str} order by id offset #{offset} limit #{rows};")
render :text => {"total" => total, "rows" => user}.to_json
end
本文介绍如何使用EasyUI实现数据表格分页,并通过Rails后端提供数据支持。主要内容包括设置EasyUI datagrid组件参数,以及Rails控制器中如何处理分页请求,返回正确的total计数和数据记录。
1万+

被折叠的 条评论
为什么被折叠?



