Am getting 'TypeError: data is null' in console

Am getting 'TypeError: data is null' in console

EndUserEndUser Posts: 5Questions: 2Answers: 0
edited December 2019 in Free community support

I'm trying to initialize a table from an ajax source. I've set my server response to resemble:

{"data": [{"fname":"Stephen"}, (...)]}

and I'm testing it out with this initialization command:

$('#data-table')
   .DataTable({
       serverSide:true,
       ajax:{url:'/position/14'},
       columns:[{data:'fname'}]
   })

However, in the javascript console, I get an error TypeError: data is null on jquery.dataTables.js:2689:5 I tried a break point there, and it executes 4 times; the third time through has the column name, but the fourth is null & undefined. What am I missing?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    You could change

    ajax:{url:'/position/14'},
    

    to be

    ajax: '/position/14',
    

    but what you have should work.

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • EndUserEndUser Posts: 5Questions: 2Answers: 0
    edited December 2019

    Ok, it's not great because it's not precisely my use-case, but here's an example ~~that should demonstrate my issue~~. Maybe.

    No, this works. I don't know how to provide a test case when I can't provide an ajax source.

  • EndUserEndUser Posts: 5Questions: 2Answers: 0

    Ok, I think I found it. My datasource returned the occasional null row:

    {first:'blah',last:'blah'},
    null,
    {first:'blah',last:'blah'}...
    
This discussion has been closed.