jQuery EasyUI データグリッド -カスタムページネーション

データグリッド(datagrid)には優れたページネーション機能が組み込まれており、カスタマイズも非常に簡単です。このチュートリアルでは、データグリッド(datagrid)を作成し、ページネーションツールバーにカスタムボタンを追加します。

データグリッド(DataGrid)の作成

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

'pagination' プロパティを true に設定すると、ページネーションツールバーが生成されることを忘れないでください。

カスタムページネーションツールバー

    var pager = $('#tt').datagrid('getPager');    // get the pager of datagrid
    pager.pagination({
        showPageList:false,
        buttons:[{
            iconCls:'icon-search',
            handler:function(){
                alert('search');
            }
        },{
            iconCls:'icon-add',
            handler:function(){
                alert('add');
            }
        },{
            iconCls:'icon-edit',
            handler:function(){
                alert('edit');
            }
        }],
        onBeforeRefresh:function(){
            alert('before refresh');
            return true;
        }
    });

ご覧のとおり、まずデータグリッド(datagrid)の pager オブジェクトを取得し、次にページネーション(pagination)を再作成します。ページリストを非表示にして、3つの新しいボタンを追加します。

jQuery EasyUI サンプルをダウンロード

jeasyui-datagrid-datagrid11.zip

その他の拡張機能