Tabulator: Unable to process data due to invalid data type Expecting: array Received: object Data:

Created on 20 Oct 2017  路  1Comment  路  Source: olifolkerd/tabulator

I'm using a parser in Classic asp to produce the JSON, which looks like this:
{"data":[{"idproduct":1,"description":"Lightweight Flannel","sku":"LGHTFLAN"},{"idproduct":2,"description":"The Unbutton-Down Shirt","sku":"ParentSKU-UNBTNDOWN"},{"idproduct":3,"description":"Daily Grind","sku":"DLYGRND"},{"idproduct":4,"description":"Daily Grind (Silver - navy - Small)","sku":"DLYGRNDnavy"},{"idproduct":5,"description":"Daily Grind (Silver - White - Small)","sku":"DLYGRNDwhite"},{"idproduct":6,"description":"Crown Prints 2","sku":"CRWNPRNTS"},{"idproduct":7,"description":"Duplicate SKU","sku":"Test123"},{"idproduct":8,"description":"$20 Gift Certificate","sku":"GC20"},{"idproduct":9,"description":"Plaid Tie","sku":"tie1"},{"idproduct":10,"description":"Sunset 1","sku":"sun1"}]}

I'm getting this error in the console:
tabulator.min.js:2 Data Loading Error - Unable to process data due to invalid data type
Expecting: array
Received: object
Data: {data: Array(10)}

Can I tell it to look for an object instead?

Question - Ask On Stack Overflow

Most helpful comment

Hey,

that is because it is returning the data array held in the data property of an object, if you have to send data in this format, then you can use the ajaxResponse callback in your table constructor to tell tabulator where to look for the data array:

$("#example-table").tabulator({
    ajaxResponse:function(url, params, response){
        //url - the URL of the request
        //params - the parameters passed with the request
        //response - the JSON object returned in the body of the response.

        return response.data; //return the data property of a response json object
    },
});

Let me know if that helps

Cheers

Oli

>All comments

Hey,

that is because it is returning the data array held in the data property of an object, if you have to send data in this format, then you can use the ajaxResponse callback in your table constructor to tell tabulator where to look for the data array:

$("#example-table").tabulator({
    ajaxResponse:function(url, params, response){
        //url - the URL of the request
        //params - the parameters passed with the request
        //response - the JSON object returned in the body of the response.

        return response.data; //return the data property of a response json object
    },
});

Let me know if that helps

Cheers

Oli

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cemmons picture cemmons  路  3Comments

mindcreations picture mindcreations  路  3Comments

tomvanlier picture tomvanlier  路  3Comments

yaxino picture yaxino  路  3Comments

sphynx79 picture sphynx79  路  3Comments