Easy UI pagenation

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章