自定义分页


数据网格(datagrid)内置一个很好特性的分页功能,自定义也相当简单。在本教程中,我们将创建一个数据网格(datagrid),并在分页工具栏上添加一些自定义按钮。

创建数据网格(DataGrid)

  1. <table id="tt" title="Load Data" class="easyui-datagrid" style="width:550px;height:250px"
  2. url="data/datagrid_data.json"
  3. iconCls="icon-save" pagination="true">
  4. <thead>
  5. <tr>
  6. <th field="itemid" width="80">Item ID</th>
  7. <th field="productid" width="80">Product ID</th>
  8. <th field="listprice" width="80" align="right">List Price</th>
  9. <th field="unitcost" width="80" align="right">Unit Cost</th>
  10. <th field="attr1" width="100">Attribute</th>
  11. <th field="status" width="60" align="center">Stauts</th>
  12. </tr>
  13. </thead>
  14. </table>

请记得,设置 'pagination' 属性为 true,这样才会生成分页工具栏。

自定义分页工具栏

  1. var pager = $('#tt').datagrid('getPager'); // get the pager of datagrid
  2. pager.pagination({
  3. showPageList:false,
  4. buttons:[{
  5. iconCls:'icon-search',
  6. handler:function(){
  7. alert('search');
  8. }
  9. },{
  10. iconCls:'icon-add',
  11. handler:function(){
  12. alert('add');
  13. }
  14. },{
  15. iconCls:'icon-edit',
  16. handler:function(){
  17. alert('edit');
  18. }
  19. }],
  20. onBeforeRefresh:function(){
  21. alert('before refresh');
  22. return true;
  23. }
  24. });

正如您所看到的,我们首先得到数据网格(datagrid)的 pager 对象,然后重新创建分页(pagination)。我们隐藏页面列表,并添加三个新的按钮。

下载 jQuery EasyUI 实例

下载地址