2

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

10 Comments

Nope not working it displays the url which i have given in href
@user2713255 Please post your table structure as well.
Added table structure
@user2713255 - I have updated my answer for the workaround that you can try
Yup directly putting the markup works. t.row.add([markup.wrap('div').parent().html()]).draw(false); this one does not work. Thanks for your inputs
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.