Unable to bind ajax JSON object to Data table.

Unable to bind ajax JSON object to Data table.

rookieStockierookieStockie Posts: 1Questions: 1Answers: 0

I read the documentation but was not able to figure out what exactly I am doing it wrong.

Please find my json object details here

Error Details: -

DataTables warning: table id=example - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

HTML Code -

<table id="example"><thead> <tr> <th>exchange</th> <th>lastPrice</th> <th>percentChange</th> <th>performanceId</th> <th>priceChange</th> <th>standardName</th> <th>ticker</th> <th>volume</th> </tr> </thead></table>

JS Code -

$('#example').DataTable( {
ajax: {
url: '/scanner/getmovers.php',
dataSrc: 'losers',
columns: [
{ data: 'exchange' },
{ data: 'lastPrice' },
{ data: 'percentChange' },
{ data: 'performanceId' },
{ data: 'priceChange' },
{ data: 'standardName' },
{ data: 'ticker' },
{ data: 'volume' } ]},} );

Answers

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,734

    You need to move your columns config outside of the ajax option. Like this:

    $('#example').DataTable( {
      ajax: {
        url: '/scanner/getmovers.php',
        dataSrc: 'losers',
      },
      columns: [
        { data: 'exchange' },
        { data: 'lastPrice' },
        { data: 'percentChange' },
        { data: 'performanceId' },
        { data: 'priceChange' },
        { data: 'standardName' },
        { data: 'ticker' },
        { data: 'volume' } 
      ]
    } );
    

    Kevin

This discussion has been closed.