如何将多个数据添加到jQuery Datatable Cell
问题描述:
我正在使用Datatables来表示来自JSON的数据。这是我的JSON:如何将多个数据添加到jQuery Datatable Cell
[{"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>';
}}
]
});
所以认为会是这样:
但我想创建一个类似如下的表。我怎么做?单列和单一销售中的所有细节。
答
您可以使用该render
:
例如:
{
data: null,
name: null,
orderable: false,
render: function (data, type, row) {
return row.Field1 +
"<img src='" + row.Field2 + "' />";
}
},
换句话说,你创建一列,用row.fieldName
像上面例子显示所有的数据到它。
我希望这会有用。
+0
thanx它的工作 –
数据表适用于表格数据。你想要的不是表格,所以Datatables不适合这个。 –