简体   繁体   中英

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

I am using dataTable and need to add a jquery dom to one column. 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.

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

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

Because row.add description says this for dom objects

Data to use for the new row. This may be an array, object, Javascript object instance or a tr element.

Specially this part

Javascript object

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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