我正在使用数据表来表示来自 JSON 的数据。这是我的 JSON:
[{"postIMAGE": "/images/abc.jpg", "postTITLE": "Some Text", "postURL" : "blah", "postSection" : "blah"}]
这是我的代码:
var table = $('#tableId').DataTable({
"ajax": {
"url": "loadSiteContent",
"dataSrc": "",
data: {sectionUrl: "", siteUrl: siteurl}
},
"columns": [
{"data": "postIMAGE", "render": function (data) {
alert(data);
return '<img src=' + data + ' width="154" height="115"/>';
}},
{"data": "postTITLE"},
{"data": "postURL", "render": function (data) {
return '<a href=' + data + ' target="_blank" rel="nofollow"/>' + data + '</a>';
}}
]
});
所以 View 将是这样的:
但我想创建如下表格。我怎么做?单列和单笔销售中的所有详细信息。
最佳答案
您可以为此使用render
:
例如:
{
data: null,
name: null,
orderable: false,
render: function (data, type, row) {
return row.Field1 +
"<img src='" + row.Field2 + "' />";
}
},
换句话说,您创建单个列并使用 row.fieldName
将所有数据显示到其中,就像上面的示例一样。
我希望这是有用的。
关于jquery - 如何将多个数据添加到 jQuery 数据表单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39136831/