Dynamic html table rows - pagination not working

Dynamic html table rows - pagination not working

venkatsvenkats Posts: 6Questions: 3Answers: 0
edited May 2014 in DataTables 1.10

Hi, I have a html table for which the datarow is added dynamically. I have download the dataTables 1.10 version. I followed the example of "http://datatables.net/examples/basic_init/alt_pagination.html" . But the pagination is not showing. I am getting error: SCRIPT5007: Unable to get value of the property 'mData': object is null or undefined
jquery.dataTables.min.js, line 87 character 162

Below is the code used:
Html tags have been removed purposefully to show the Ui structure as well
[CODE]
table id="tbl1" class="display"
thead
/thead
/table

//javascript file

$(document).ready(function () {
RenderHtmlOnSuccess();

});

function RenderHtmlOnSuccess() {
// Data is getting filled. I can see 20 records

$("#tbl1").append("<tbody>");
for (var i = 0; i < newsdata.length; i++)
{
var newArray = newsdata[i].split('#');
for (var j = 0; j < newArray.length; j++) {
$("#tbl1").append("<tr><td>" + newArray[j] + "</td></tr> ");
}
if (i < (newsdata.length - 1)) {
$("#tbl1").append("<tr><td class='spacers'></td></tr> ");
}
}
$("#tbl1").append("</tbody>");

$('#tbl1').dataTable({ "pagingType": "full_numbers" });

}
[/CODE]

Answers

  • shickeyshickey Posts: 18Questions: 1Answers: 0
    edited May 2014

    The problem you have is with how your table is created, not with the DataTables plugin. You don't have a body to your table and your rows and cells aren't being created correctly (at all). Remove the DataTable initialization and get your table correct before you try and use the plugin.

  • venkatsvenkats Posts: 6Questions: 3Answers: 0
    edited May 2014

    Hi, The table is formed properly. The "Tbody" is added in the first line of the function. The formatting of the code which I have put has removed it.
    For example, please check this jsfiddle: http://jsfiddle.net/Nh9AQ/

This discussion has been closed.