JSRUN 用代码说话

合并单元格

编辑教程

jQuery EasyUI 数据网格 - 合并单元格

本节将介绍jQuery EasyUI数据网格(datagrid)如何对单元格进行合并。

调用'mergeCells'方法就可以合并数据网格单元格,并传入合并信息参数,该方法告诉数据网格如何合并单元格。 在所有合并的单元格中,除了第一个单元格,其它单元格在合并后被隐藏。

创建数据网格(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>

合并单元格

当数据加载之后,合并数据网格中的一些单元格,所以放置下面的代码在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                 
                            });         
               }     
        });
JSRUN闪电教程系统是国内最先开创的教程维护系统, 所有工程师都可以参与共同维护的闪电教程,让知识的积累变得统一完整、自成体系。 大家可以一起参与进共编,让零散的知识点帮助更多的人。
X
支付宝
9.99
无法付款,请点击这里
金额: 0
备注:
转账时请填写正确的金额和备注信息,到账由人工处理,可能需要较长时间
如有疑问请联系QQ:565830900
正在生成二维码, 此过程可能需要15秒钟