如何将多个数据添加到jQuery Datatable Cell

时间:2016-08-25 04:44:33

标签: jquery css ajax datatables

我使用数据表来表示来自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>';
                }}
        ]
    });

所以视图将是这样的:

Enter image description here

但我想创建如下表格。我怎么做?单列和该单一销售中的所有详细信息。

Enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用render
例如:

{
    data: null,
    name: null,
    orderable: false,
    render: function (data, type, row) {
       return row.Field1 +
              "<img src='" + row.Field2 + "' />";           
    }
},

换句话说,您创建了一个列,并使用row.fieldName之类的示例将所有数据显示在其中 我希望这很有用。

相关问题