user12358450
user12358450

Reputation:

DataTables warning: Non-table node initialisation (DIV). For more information about this error, please see http://datatables.net/tn/2

I have created a form to echo table data, I need to design the table With Sorting, Searching and Paging, but the error show me like this DataTables warning: Non-table node initialisation (DIV). For more information about this error, please see http://datatables.net/tn/2, below is my coding:

head

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">   
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css"></style>
<script type="text/javascript" src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

Echo Table coding

<?php
session_start();
$qry = "select id, name, identify, created, pay_option, amount, receivedby from payment_details";
$_SESSION["query"] = $qry;
$result = $conn->query("select id, name, identify, created, pay_option, amount, receivedby from payment_details");
$rows = $result->fetchAll(PDO::FETCH_ASSOC);
echo "<div id='myTable'><div class='data-content'><span><b>REPORT SELECTION</b></span><div class='data-table'>";
echo "<table id='dataTable'><tr><th>Payer</th><th>Passport/IC No</th><th>Date Paid</th><th>Payment Type</th><th>Payment Amount</th><th>Received by</th><th>Payment Receipt</th></tr>";
foreach($rows as $row) {
echo "<tr id=".$row["id"]."><td>".$row["name"]."</td><td>".$row["identify"]."</td><td>".$row["created"]."</td><td>".$row["pay_option"]."</td><td>".$row["amount"]."</td><td>".$row["receivedby"]."</td><td><a href='?loc=invoice' onclick='sessionFunction(".$row["id"].")'>View</a></td></tr>";
                }
echo "</table>";
echo "</div></div><div class='table-msg'><span>Total Record : ";
echo $result->rowCount();
echo "</span><span style='margin-left: 70%;'>Max 500 pages</span></div></div>";
                ?>

Script Function

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

My Output show me like this Output

Actual I want the output table like the below sample and red arrows in the picture mean that I want the function: Output 2

I hope someone coding experts can guide me how to sovle it, this problems have already make me stuck in the few days. Thanks.

Upvotes: 1

Views: 2737

Answers (1)

andrewJames
andrewJames

Reputation: 21908

In your HTML you have defined these two tags:

<div id='myTable'>

and:

<table id='dataTable'>

So, the ID of your table tag is dataTable.

However when you initalize DataTables...

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

... the ID you use is myTable - which is the ID of the <div> tag. You need to use the ID of the <table> tag.

I suggest swapping the IDs around in your HTML to be like this:

<div id="dataTable">

and:

<table id="myTable">

(It's typical to use double-quotes, not single-quotes.)

But that explains the error message:

DataTables warning: Non-table node initialisation

You are trying to use a <div> to initialise DataTables. You should be able to get past this error, by making this change.

(There may be other problems hiding behind this error, of course.)

I also note that the examples (e.g. here) refer to the function DataTable() not dataTable(). I'd recommend following their syntax exactly (and I am assuming you are using version 1.10.20).

Upvotes: 2

Related Questions