简体   繁体   English

数据表row.add([])传递一个jQuery dom?

[英]Datatable row.add([]) passing a jquery dom?

I am using dataTable and need to add a jquery dom to one column. 我正在使用dataTable,并且需要将jquery dom添加到一列。 The following is my code: 以下是我的代码:

var markup = $("<a></a>").addClass("ClassName")
            .attr({ href : "Something.html",title : "Edit"});

var t = $("#myTable").DataTable();

t.row.add( [markup] ).draw( false );

The above code displays "[object Object]" in the column instead of the required href. 上面的代码在列中显示“ [object Object]”,而不是必需的href。

here is my table structure: 这是我的表结构:

<table id="myTable" >
 <tbody> 
 </tbody>
 </table>

What am I doing wrong here? 我在这里做错了什么?

You are passing jquery object, try passing javascript object like this 您正在传递jquery对象,请尝试像这样传递javascript对象

t.row.add( [markup[0]] ).draw( false );

Because row.add description says this for dom objects 因为row.add描述对dom对象说了这一点

Data to use for the new row. 用于新行的数据。 This may be an array, object, Javascript object instance or a tr element. 这可以是数组,对象,Javascript对象实例或tr元素。

Specially this part 特别是这部分

Javascript object Javascript对象

Update 更新

I tried in all the way possible but it is not working in any way, seems a bug in DataTables , but there is a workaround that you can use, try adding your markup like this 我尝试了所有可能的方法,但是它并没有以任何方式工作,似乎是DataTables的错误,但是您可以使用一种解决方法,尝试像这样添加标记

t.row.add([markup.wrap('div').parent().html()]).draw(false);

or just put direct markup, like this 或像这样直接标记

t.row.add(['<a class="ClassName" href="Something.html" title="Edit">Edit</a>']).draw(false);

Fiddle Example 小提琴的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM