【问题标题】:How to add multiple data to jQuery Datatable Cell如何将多个数据添加到 jQuery Datatable Cell
【发布时间】:2016-08-25 04:44:33
【问题描述】:

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

所以视图会是这样的:

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

【问题讨论】:

  • Datatables 用于表格数据。你想要的不是表格,所以 Datatables 不适合这个。

标签: jquery css ajax datatables


【解决方案1】:

您可以为此使用render
例如:

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

换句话说,您创建单个列并使用row.fieldName 将所有数据显示到其中,就像上面的示例一样。
我希望这很有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多