Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Now I want to integrate the plugin Datatables using JQuery
for example I can add this into my code above :

HTML
$("table#myTableId").dataTable(); 


If I take the ID of the table from the HTML source and call the dataTable() function, all the mentioned features will be automatically added and they will be fully functional. jQuery DataTables takes the plain HTML table and dynamically injects all elements,


I assign an id to my table I created above so that I can use the ID to call the datatable() later on.


I managed to add the ID but there's no change to my Table when I call the dataTable(). What did I do wrong?
<script type="text/javascript"charset="utf-8">



    d3.text(file, function (datasetText) {


    var rows = d3.csv.parseRows(datasetText);

    var tbl = d3.select("#container")
        .append("table");
     
    tbl.attr("id","tableID");


    // headers
      tbl.append("thead").append("tr")
        .selectAll("th")
        .data(rows[0])
        .enter().append("th")
        .text(function(d) {
            return d;
        });

    // data
    tbl.append("tbody")
        .selectAll("tr").data(rows.slice(1))
        .enter().append("tr")

        .selectAll("td")
        .data(function(d){return d;})
        .enter().append("td")
        .text(function(d){return d;})


     
          $(document).ready(function() {
               $('#tableID').dataTable();
         } );
      
});
    
 

    

	


    </script>
Posted
Updated 24-Mar-15 21:45pm
v5
Comments
Sergey Alexandrovich Kryukov 24-Mar-15 17:12pm    
What do you mean by "DataTable"? All I can see is HTML table element.
Second question: why? If you mean working with databases (or any other storage, does not matter) with JavaScript, you need to know that this is unsafe, unreliable, difficult... You should better use some server-side technology.
—SA
ramyajaya 24-Mar-15 19:55pm    
Hai,
According to my understanding u have appended a table tag with to your body tag, but you haven't appended tr or td tag inside the table tag then if you perform selectall on tr it will be null .

To avoid all this confusion create a blank table with tr td tags and append the values to it using d3
whateverme19 25-Mar-15 5:46am    
I changed my code. But I still Can't get it working. - Please see my edited code above.
ramyajaya 25-Mar-15 6:33am    
Your code is correct but could you please check in your browser error console if it holds any error?
whateverme19 25-Mar-15 6:43am    
I got two errors:
1) Denying load of chrome-extension://gkojfkhlekighikafcpjkiklfbnlmeio/js/jquery.min.map. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

2)Uncaught TypeError: undefined is not a function
- This points to my line of code: $('#tableID').dataTable();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900