Jquery 插件 DataTable 单元格设为跨行遇到的问题

来源:互联网 发布:discuz数据备份 编辑:程序博客网 时间:2024/05/29 14:02

我需要使用DataTable实现某些单元格跨列,绘制如图(1-1)所示的表格,并且数据是动态加载的,在这里数据格式如data。

注意:下面片段代码的else必须添加,否则DataTable会抛出warning异常:requested unkonw parameters "2" from the data source for row 2. 

@if(mark==true){

    mark =false;

       <tdrowspan="@item.list.Count()"id="@item.NodeItemId"class="nodeId">@item.DealStepsName</td>

    }else{

       <tdstyle="display:none"></td>

    }

}

列1列2列3aa2a3bdb2b3d2d3

图(1-1)


代码片段:

data={

    [ {value1:a, list:[ { value2:a2,value3:a3 } ] },

      {value1:bd, list:[ { value2:b2,value3:b3 },{ value2:d2,value3:d3 } ] } ]

}

$(document).ready(function () {

     $("#tblDealList").dataTable();

}

<table id="tblDealList" class="display">
                <thead>
                    <tr>
                        <th>列1</th>
                        <th>列2</th>
                        <th>列3</th>
                    </tr>
                </thead>
                <tbody>
                    @{
                        var mark=true;
                        if (data!= null)
                        {
                            foreach (var item in data)
                            {
                                mark = true;
                                foreach(var u in item.list){
                                    <tr>
                                       @if(mark==true){
                                            mark = false;
                                        <td rowspan="@item.list.Count()">@item.value1</td>
                                        }else{
                                           <td style="display:none"></td>
                                       }
                                        <td>@u.value2</td>
                                        <td>@u.value3</td>
                                    </tr>
                                }
      
                            }
                        }
                    }
                </tbody>
            </table>



0 0