Hi i'm getting the following error in my console.In the output page the buttons are not displaying

Hi i'm getting the following error in my console.In the output page the buttons are not displaying

VandanaRaoVandanaRao Posts: 1Questions: 1Answers: 0

ERROR:
Uncaught TypeError: Cannot read property 'mData' of undefined
at HTMLTableCellElement.<anonymous> (jquery.dataTables.min.js:89)
at Function.each (jquery-1.12.4.js:370)
at jQuery.fn.init.each (jquery-1.12.4.js:137)
at HTMLTableElement.<anonymous> (jquery.dataTables.min.js:89)
at Function.each (jquery-1.12.4.js:370)
at jQuery.fn.init.each (jquery-1.12.4.js:137)
at jQuery.fn.init.m [as dataTable] (jquery.dataTables.min.js:82)
at jQuery.fn.init.h.fn.DataTable (jquery.dataTables.min.js:164)
at localhost/:55

HTML:
<title>DataTable</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css">
</head>

<body>
<table id="example">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>

SRICPT:





$('#example').DataTable( { dom: 'Bfrtip', buttons: [ 'copy','Excel' ] });

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You need to add a tbody tag around your rows. More like this:

    <table id="example">
    <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
    </tr>
    
    <tbody>
    
    <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
    </tr>
    .....
    <td>Magazzini Alimentari Riuniti</td>
    <td>Giovanni Rovelli</td>
    <td>Italy</td>
    </tr>
    
    </tbody>
    
    </table>
    

    Kevin

This discussion has been closed.