табулятор Невозможно обработать данные из-за неверного типа данных - PullRequest
0 голосов
/ 31 марта 2020

Я пытаюсь узнать, как загрузить данные в табулятор из JSON данных. Я сталкиваюсь с ошибкой

tabulator.min.js:3 Data Loading Error - Unable to process data due to invalid data type 
Expecting: array 
Received:  object 

Я думаю, что мне нужно использовать ajaxResponse:function, но не совсем уверен, как. Вот фрагмент кода, который я использую.

//define data

var data = [ ]

  var table = new Tabulator("#tabulator-example", {
        height:800,
        data:data,
        layout:"fitDataStretch",
         //ajaxURL:"omdata.json",
        // ajaxProgressiveLoad:"scroll",
        // paginationSize:20,
        placeholder:"No Data Set",
        autoResize:true,
        ajaxContentType : "application/json; charset=utf-8",
        ajaxContentType:"json",
        tooltips:true,
        addRowPos:"top",
        resizableRows:true,
      initialSort:[
         {column:"feature", dir:"asc"},,
      ],
      columns:[
       <REMOVED>
      ],
    });
    //trigger AJAX load on "Load Data via AJAX" button click
    document.getElementById("ajax-trigger").addEventListener("click", function(){
    table.setData("omdata.json");
    });

    $("#tabulator-controls input[name=feature]").on("keyup", function(){
      table.setFilter( "feature", "like", $(this).val())
    });

1 Ответ

0 голосов
/ 31 марта 2020

Хорошо, я понял это. Вот что я сделал

var table = new Tabulator("#tabulator-example", {
        height:800,
        data:data,
        layout:"fitDataStretch",
         //ajaxURL:"omdata.json",
        // ajaxProgressiveLoad:"scroll",
        // paginationSize:20,
        placeholder:"No Data Set",
        autoResize:true,
        ajaxContentType : "application/json; charset=utf-8",
        ajaxContentType:"json",
        tooltips:true,
        addRowPos:"top",
        resizableRows:true,
      initialSort:[
         {column:"feature", dir:"asc"},,
      ],
      columns:[
       <REMOVED>
      ],

      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; //pass the data array into Tabulator
    },
}),
...