jQuery EasyUI データグリッド -セルの結合
データグリッド(datagrid)では、セルを結合する必要がよくあります。このチュートリアルでは、データグリッド(datagrid)でセルを結合する方法を説明します。
データグリッド(datagrid)のセルを結合するには、'mergeCells' メソッドを呼び出し、結合情報パラメータを渡して、データグリッド(datagrid)にセルの結合方法を指示するだけです。結合されたセルのうち、最初のセルを除く他のセルは結合後に非表示になります。
データグリッド(DataGrid)の作成
<table id="tt" title="Merge Cells" style="width:550px;height:250px" url="data/datagrid_data.json" singleSelect="true" iconCls="icon-save" rownumbers="true" idField="itemid" pagination="true"> <thead frozen="true"> <tr> <th field="productid" width="80" formatter="formatProduct">Product ID</th> <th field="itemid" width="100">Item ID</th> </tr> </thead> <thead> <tr> <th colspan="2">Price</th> <th rowspan="2" field="attr1" width="150">Attribute</th> <th rowspan="2" field="status" width="60" align="center">Stauts</th> </tr> <tr> <th field="listprice" width="80" align="right">List Price</th> <th field="unitcost" width="80" align="right">Unit Cost</th> </tr> </thead> </table>
セルの結合
データ読み込み後、データグリッド(datagrid)内のいくつかのセルを結合するため、以下のコードを onLoadSuccess コールバック関数内に配置します。
$('#tt').datagrid({
onLoadSuccess:function(){
var merges = [{
index:2,
rowspan:2
},{
index:5,
rowspan:2
},{
index:7,
rowspan:2
}];
for(var i=0; i<merges.length; i++)
$('#tt').datagrid('mergeCells',{
index:merges[i].index,
field:'productid',
rowspan:merges[i].rowspan
});
}
});
jQuery EasyUI サンプルをダウンロード
jeasyui-datagrid-datagrid13.zip
その他の拡張