jQuery EasyUI DataGrid -Fusionner des cellules

DataGrid (datagrid) a souvent besoin de fusionner certaines cellules. Ce tutoriel vous montrera comment fusionner des cellules dans un DataGrid (datagrid).

Pour fusionner les cellules d'un DataGrid (datagrid), il suffit d'appeler la méthode 'mergeCells' et de passer le paramètre d'informations de fusion pour indiquer au DataGrid (datagrid) comment fusionner les cellules. Parmi toutes les cellules fusionnées, à l'exception de la première cellule, les autres cellules sont masquées après la fusion.

Créer un 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>

Fusionner des cellules

Une fois les données chargées, nous fusionnons certaines cellules dans le DataGrid (datagrid), donc placez le code suivant dans la fonction de rappel 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
                });
        }
    });

Télécharger les exemples jQuery EasyUI

jeasyui-datagrid-datagrid13.zip

Autres extensions