Table show only nulls

Table show only nulls

shenhavshenhav Posts: 3Questions: 1Answers: 0

Hi,
When I use the following code (copied from your example) the table renders fine:
$(function onDocReady() {

var table = $('#example').DataTable({
    'ajax': 'http://sp-static-content-4-web.s3-website.us-east-2.amazonaws.com/js/new.json',
    'columns': [
        {
            'className':      'details-control',
            'orderable':      false,
            'data':           null,
            'defaultContent': ''
        },
        { 'data': 'username' },
        { 'data': 'eventtype' },
        { 'data': 'sourceip' },
        { 'data': 'time' }
    ],
    'order': [[1, 'asc']]
} );

But when I use the following code (same url, same response) I get only nulls:
$(function onDocReady() {
var table = $('#example').DataTable({
"processing": true,
"ajax": {
"url" : "http://sp-static-content-4-web.s3-website.us-east-2.amazonaws.com/js/new.json",
"type": "POST",
"data": function ( d ) {
d.action = "listEvents";
// d.custom = $('#myInput').val();
// etc
},
"columns": [
{
"className": "details-control",
'orderable': false,
'data': null,
'defaultContent': ''
},
{ 'data': 'username' },
{ 'data': 'eventtype' },
{ 'data': 'sourceip' },
{ 'data': 'time' }
],
'order': [[1, 'asc']],
'beforeSend': function (request) {
request.setRequestHeader("Authorization", authToken);
}
}
} );

I use the same url in both functions because I wanted to make sure the error is not server side, it is client side. something with my javascript that I don't understand.
the error says:requested unknown parameter '0' for row 0...

Answers

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

    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

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954

    The URL may be the same but the request is different. You are adding the POST type and data parameters so the response may be different. Start by looking at the JSON response using the browser's network inspector. Steps can be found in this technote. What do you find different between the working and non-working configs?

    Kevin

  • shenhavshenhav Posts: 3Questions: 1Answers: 0
    edited May 2020

    Hi,
    thanks for your answer, but the response is exactly the same.
    I use the same url that refers to the same static json file (there is no need for authorization in this url, and no need for parameters)

    here is a link for the test case:
    sp-static-content-4-web.s3-website.us-east-2.amazonaws.com
    you'll need to login (you can register or use: kacetoj181@toracw.com pass:1qazZAQ!)
    then the page with datatables is on sp-static-content-4-web.s3-website.us-east-2.amazonaws.com/events.html

    'What do you find different between the working and non-working configs?'
    I can't figure that out. I send authorization header and add params to the request - however I do make sure that the response is the same (I even asked for the static json file to make sure) and I get an error

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954
    edited May 2020

    Thanks for the example. That took a bit to find but you have you columns, etc configs options inside the ajax option:

          'ajax': {
                'url' : _config.api.invokeUrl + '/ride',
                'type': 'POST',
                'data': function ( d ) {
                    d.action = 'listEvents';
                    // d.custom = $('#myInput').val();
                    // etc
                },
                },  // need to add this to complete the ajax option.  Will also need to remove one below.
            'columns': [
    

    Kevin

  • shenhavshenhav Posts: 3Questions: 1Answers: 0

    Thank you so much!

This discussion has been closed.