DataTables warning: table id=token-table - [object Object]

DataTables warning: table id=token-table - [object Object]

tarunsharma967tarunsharma967 Posts: 1Questions: 1Answers: 0
edited September 2019 in Free community support

I am getting following error for my datatable, i am not getting this error message.
DataTables warning: table id=token-table - [object Object]

       var table1 = $('#token-table').DataTable( {
           "ajax"       : {
                "url"    : token,
                "dataSrc": function ( data ) {
                    let arr = [];
                    for (key in data) {
                        arr.push({
                            name : key,
                            freq : data[key]['frequencycount'],
                            freqPercent : data[key]['percentvalue'],
                        });
                    }
                    return arr;
                    }
                },
                "columns": [
                    { "data": "name" },
                    { "data": "freq" },
                    { "data": "freqPercent" },
                ],
                deferRender : true,
                scrollY     : 500,
                scroller    : true,
               } );

       setInterval( function () { table1.ajax.reload(null,false) }, 10000 );    

            <table id="token-table">
                <thead>
                    <tr>
                        <th class="col-md-6">Token Name</th>
                        <th class="col-md-3">Frequency count</th>
                        <th class="col-md-3">Frequency Percent</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>

This is my code for dataTable.

Answers

  • colincolin Posts: 12,608Questions: 0Answers: 2,154

    Hi @tarunsharma967 ,

    It looks like it 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

  • denny_kurniawandenny_kurniawan Posts: 8Questions: 0Answers: 0

    I am also have the same problem, this is my test case.

    and this is my JS code:

    let tableDeveloper = $('#tableDeveloper').DataTable({
        ajax : {
            url : 'text.txt',
            dataType: "json",
            dataSrc : function(json) {
                console.log(json)
                let temp, data = []
    
                 for (var i=0;i<json.data.developer.length;i++) {
                    temp = json.data.developer[i];
                    item = {};
    
                    item["nomor"] = (i+1);
                    item["id"] = temp.id;     
                    item["name"] = temp.developer_name;
                    item["icon"] = null;
                   item["active"] = temp.is_active;
                   item["description"] = temp.description;
    
                    data.push(item);
                }
                 return data;
            }
        },
        "columns": [
            { "data": "nomor"},
            { "data": "name" },
            { "data": "icon" },
            { "data": "description" },
            { "defaultContent": "<buttontype='button' class='btn btn-primary'>Edit</button> <button class='btn btn-danger'> Delete</button>"}
        ]
    

    Thank you.

  • tangerinetangerine Posts: 3,112Questions: 25Answers: 364

    I'm getting "This site can’t be reached : www.signaltekno.com took too long to respond." from Chrome.

  • denny_kurniawandenny_kurniawan Posts: 8Questions: 0Answers: 0
    edited July 24

    Thanks, @tangerine. Sorry about that, my server hosting location is in Asia. So maybe it's taking too long when you are from another country. I didn't realize this before posting.

  • denny_kurniawandenny_kurniawan Posts: 8Questions: 0Answers: 0

    And this is my JSON file, in case. website can't be accessed.

    {
        "code": 200,
        "data": {
            "developer": [
                {
                    "id": 4,
                    "developer_name": "Ubisoft",
                    "icon": null,
                    "header": null,
                    "description": "",
                    "is_active": 0,
                    "updated_at": "2021-07-23T12:17:57.000000Z"
                },
                {
                    "id": 7,
                    "developer_name": "Digital Hippies Games",
                    "icon": null,
                    "header": null,
                    "description": "",
                    "is_active": 0,
                    "updated_at": "2021-07-24T06:47:02.000000Z"
                },
                {
                    "id": 8,
                    "developer_name": "SuperCell",
                    "icon": null,
                    "header": null,
                    "description": "",
                    "is_active": 1,
                    "updated_at": "2021-07-24T07:45:47.000000Z"
                },
                {
                    "id": 9,
                    "developer_name": "Capcom",
                    "icon": null,
                    "header": null,
                    "description": "",
                    "is_active": 1,
                    "updated_at": "2021-07-24T07:47:18.000000Z"
                },
                {
                    "id": 10,
                    "developer_name": "Moonton",
                    "icon": null,
                    "header": null,
                    "description": "",
                    "is_active": 1,
                    "updated_at": "2021-07-24T12:09:38.000000Z"
                },
                {
                    "id": 11,
                    "developer_name": "Capcom",
                    "icon": null,
                    "header": null,
                    "description": "",
                    "is_active": 1,
                    "updated_at": "2021-07-24T14:21:15.000000Z"
                }
            ],
            "message": "success"
        },
        "error": {
            "message": ""
        }
    }
    
  • denny_kurniawandenny_kurniawan Posts: 8Questions: 0Answers: 0

    This is my new updated test case. Sorry for the inconvenience.

  • kthorngrenkthorngren Posts: 13,786Questions: 25Answers: 3,242

    Looks like you row data is in data not data.developer:

    You are getting this error:

    Uncaught TypeError: Cannot read property 'length' of undefined

    You need to change everywhere you are using data.developer to just data, for example in this statement - which is generating the error:

    for (var i=0;i<json.data.developer.length;i++) {
    

    Kevin

  • denny_kurniawandenny_kurniawan Posts: 8Questions: 0Answers: 0
    edited July 24

    Thanks, Kevin for your answer, but the warning alert is still shown. Even tho I changed the JSON file and add the developer field. The data is shown, but the alert dialog keep shown every time refreshes the page.

  • kthorngrenkthorngren Posts: 13,786Questions: 25Answers: 3,242

    Have you debugged the result of your loop? What is the value of data before the return data statement in the ajax.dataSrc function?

    Kevin

Sign In or Register to comment.