jquery - DataTable not loading - Uncaught TypeError: Cannot read property 'length' of undefined -


trying load the datatable ajax request,

var url = '/my/url'; var table = $('#m_datatable').datatable( {              'ajax': {               type: 'get',               'url': url,               'data': function (d) {                                 return json.stringify( d );               }             }          } ); 

html:

<table id="m_datatable" class="display" width="100%">     <thead>             <tr>                 <th>id</th>                 <th>value1</th>                 <th>value2</th>             </tr>         </thead>     </table> 

ajax request returns following json:

[ { id: 1801, value1: 1224589451, value2: 1665229451 }, { id: 1802, value1: 1224589451, value2: 1665229451 }, { . . . } ] 

datatable showing empty , throwing following error in console:

uncaught typeerror: cannot read property 'length' of undefined http://cdn.datatables.net/1.10.12/js/jquery.datatables.min.js 

you need tell table data, adding:

, 'columns': [{   'data': 'id' }, {   'data': 'value1' }, {   'data': 'value2' }] 

...should it, hope helps. (working example: https://jsfiddle.net/annoyingmouse/vvmcyacv/)


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -