topjui/easyui 表格分页简单实例

$('#dg').datagrid({

rownumbers:true, //行号

singleSelect:true, //单选

autoRowHeight:false, //自动行高

pagination:true, //显示表格下面的分页插件

fitColumns:true, //字段自动分配

collapsible:true, //表单收缩

checkOnSelect : false,

toolbar:'#tb', //显示表格上面的搜索框等,这些按钮在tb这个div里

url:'${ctx}/....',//表格数据的请求路径(由后台提供;注意是里面有rows的数组,带total的对象数据,否则无法直接显示,大家模拟数据的时候要注意)

pageNumber:1, //默认显示第几页

pageSize: 2,//每页显示的记录条数,默认为10

pageList: [2,4,6,8],//可以设置每页记录条数的列表

columns:[[

{field:'id',title:'名称',hidden:true},

{field:'opr',title: '操作',align: 'center',width:'25%',

  formatter:function(value,row,index){//格式化

     if(row.id) {//条件根据实际情况修改

        return

             "&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' onclick='modify(\""+ row.id +"\",\""+index+"\")'>修改</a>"+

             "&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' onclick='del(\""+ row.id +"\",\""+index+"\")'>删除</a>";

        }

     }

  }

}]]

});

//设置分页控件

var p = $('#dg').datagrid('getPager');

$(p).pagination({

beforePageText: '第',//页数文本框前显示的汉字

afterPageText: '页 共 {pages} 页',

displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',

});

//如果前端要模拟数据怎么办,json数据就是这个样子

{

"rows": [

{"id":1,"opr": 1},

{"id":2,"opr": 2},

...

],

"total": 100

}

猜你喜欢

转载自blog.csdn.net/qq_42750608/article/details/82909947