【问题标题】:tabulator Unable to process data due to invalid data type由于数据类型无效,制表器无法处理数据
【发布时间】:2020-03-31 17:24:01
【问题描述】:

我正在尝试学习如何将数据从 JSON 数据加载到制表器中。我遇到了错误

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

我想我需要使用ajaxResponse:function,但不完全确定如何使用。这是我正在使用的 sn-p 代码。

//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())
    });

【问题讨论】:

    标签: html tabulator


    【解决方案1】:

    好的,我想通了。这就是我所做的

    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
        },
    }),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      相关资源
      最近更新 更多