如何以正确的顺序填充dataTable

时间:2015-10-23 10:13:44

标签: javascript jquery html datatables

我正在尝试使用我的服务器端值来dataTable,但它没有正确填充。我正在发布我的dataTable结构代码..

dt = $("#up").dataTable({
"data": dataSet,
"paging": false,
"responsive": true,
"stateSave": true,
"columns": [
{ "title": "<input type='checkbox' id='selectAll'>", "bSortable": false, "width": "5px", },
{ "title": "", "bSortable": false, "width": "5px" },
{ "title": "Code", "width": "50px" },
{ "title": "Name" },
{ "title": "Contact Name" },
{ "title": "Contact Email" }
]
});

在上表中,我希望第一列为Select All复选框类型,第二列为编辑列,其中edit(Pencil)图标,其余列为我的服务器端值但当前来自服务器端的数据正在从第一列开始显示,将最后两列保持为空。此外,我将此警报设为警告DataTables warning: table id=CompanySetup - Requested unknown parameter '4' for row 0. For more information about this error, please see http://datatables.net/tn/4 请帮我搞定..谢谢..

更新..

@{
StringBuilder sb = new StringBuilder();
foreach(row in model.MyTable)
{
 sb.AppendFormat("['{0}', '{1}', '{2}', '{3}'],",
    row.Field1, row.Field2, row.Field3, row.Field4);
}
}

var dataSet = [@Html.Raw(sb.ToString())];

0 个答案:

没有答案