Issue on Loading Dynamic Data to “DataTables” Using jQuery
Demo
I am using this solution to load dynamic data in to Data Table. I have to use the Array of Array since I am getting dynamic data from user on font end selection (NO DATABASE Selection). I am using following code to upload data into the table
- <table cellpadding="0" cellspacing="0" border="0" class="dataTable" id="example"></table>
and JS
- $(document).ready(function () {
- var counter = 0;
- var compareTable = [];
- var compareRow = [];
- var check = "Test";
- var compModelName = "Test";
- var selectedType = "Test";
- var selectedTarget = "Test";
- var selectedROR = "Test";
- var selectedSpecies = "Test";
- var historicDis = "Test";
- var projectsNumber = "Test";
- var projectsCost = "Test";
- var projectsRoads = "Test";
- var projectsPowerline = "Test";
- var projectsPenstock = "Test";
- var mapshow = "Test";
-
- $("#load").on("click", function () {
- loader();
- });
-
- function loader() {
- compareRow.push(check);
- compareRow.push(compModelName);
- compareRow.push(selectedType);
- compareRow.push(selectedTarget);
- compareRow.push(selectedROR);
- compareRow.push(selectedSpecies);
- compareRow.push(historicDis);
- compareRow.push(projectsNumber);
- compareRow.push(projectsCost);
- compareRow.push(projectsRoads);
- compareRow.push(projectsPowerline);
- compareRow.push(projectsPenstock);
- compareRow.push(mapshow);
- }
-
- $('#example').dataTable( {
- "data": compareTable,
- "columns": [
- { "title": "Compare" },
- { "title": "Model Name" },
- { "title": "Model Type" },
- { "title": "Energy Target" },
- { "title": "ROR Attribute" },
- { "title": "Species", "class": "center" },
- { "title": "Disturbance", "class": "center" },
- { "title": "Projects" },
- { "title": "Cost (M$)" },
- { "title": "Roads (Km)" },
- { "title": "Powerlines (Km)", "class": "center" },
- { "title": "Penstock (m)", "class": "center" },
- { "title": "Map" }
- ]
- } );
- });
- });
but as you can see in the Demo it is not functioning when we click on the "#load" . Can you please let me know why this is happening and how I can fix it?