将JQuery元素添加到datatable td

时间:2015-12-27 12:03:29

标签: javascript jquery datatable datatables

tableObject = $("#example1").DataTable({
    columns: [{ title: "Client Id" }, { title: "City" }]
});

var clientId = value['client_id'];
var editCitySmall = $("<small>", {
                        id: "editCity_" + clientId,
                        "onclick": "editCity('" + clientId + "')",
                        "class": "label pull-right bg-blue editTd"
                    });

tableObject.row.add([clientId, editCitySmall]).draw(false);

它不是wrk,在列&#34; city&#34; print this =&gt; [object Object]

如何在列中插入<small>

1 个答案:

答案 0 :(得分:0)

我认为你几乎就在那里,除了你要返回一个对象而不是DataTables期望的字符串。尝试这样的事情:

var editCitySmall = $("<small/>", {
    "id": "editCity_" + clientId,
    "onclick": "editCity('" + clientId + "')",
    "class": "label pull-right bg-blue editTd"
}).prop("outerHTML");

这样你就会返回刚刚创建的small对象的文本。

让我知道你如何继续,如果可能的话尝试添加一个JSFiddle ......