adding a jquery datatable dynamically -
i need add datatable dynamically. can add html table dynamically, not being converted datatable.
i getting error: object doesn't support property or method 'datatable' file: test.html, line: 12, column: 13
here test code:
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da"> <head> <link rel="stylesheet" type="text/css" href="cdn.datatables.net/1.10.2/css/jquery.datatables.min.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript" language="javascript" src="/script/jquery.datatables.js"></script> <script type="text/javascript"> jquery(function () { var s = "<table id='example'><thead><tr><th>sites</th></tr></thead><tbody><tr><td>line1</td></tr><tr><td>line2</td></tr><tr><td>line3</td></tr></tbody></table>" $('.add_to_this').append(s); $('#example').datatable(); }); </script> </head> <body> <div class="add_to_this"> <p>test</p> </div> </body> </html>
you need add datatables css file.
//cdn.datatables.net/1.10.2/css/jquery.datatables.min.css
here working js fiddle
hope helps.
Comments
Post a Comment