制表符:通过Ajax加载Google表格数据

问题描述 投票:0回答:1

我现在正在尝试几天,我无法弄清楚如何将Google表格文档加载到Tabulator中。

我做了什么:

我的Tabulator代码:

    var table = new Tabulator("#baanrecords", {
        ajaxConfig:{
            mode: 'no-cors',
            method:'GET',
            credentials: 'same-origin',
            headers: {
                'Content-type': 'application/json; charset=UTF-8',
                'Accept': 'application/json',
                'X-Requested-With': 'XMLHttpRequest'
            },
        },
        ajaxURL: 'https://spreadsheets.google.com/feeds/list/1Ze31_SUFd0ZyqeG1mt1qrEU61onnYhmI9mR1BC1pM7Y/od6/public/values?alt=json',
        height:'400px',
        layout:'fitColumns',
        autoColumns:true,
        placeholder:'De records worden geladen, een moment...',
        index: 'onderdeelnaam',
        columns:[
            {title:"Onderdeel", field:"gsx$onderdeelnaam", sorter:"string", width:200},
            {title:"Prestatie", field:"gsx$prestatie", sorter:"number", formatter:"progress"},
            {title:"Eenheid", field:"gsx$prestatieeenheid", sorter:"string"},
            {title:"Naam", field:"gsx$naam", sorter:"string", align:"left", width:100},
            {title:"Categorie", field:"gsx$categorie", sorter:"string", sortable:true},
            {title:"Datum", field:"gsx$datum", sorter:"date", align:"left"},
            {title:"Plaats", field:"gsx$plaats", align:"right", sorter:"string"},
        ],
        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.entry; //return the tableData property of a response json object
        },
    });
    table.setData("https://spreadsheets.google.com/feeds/list/1Ze31_SUFd0ZyqeG1mt1qrEU61onnYhmI9mR1BC1pM7Y/od6/public/values?alt=json");

不幸的是,我无法弄清楚我做错了什么。在此先感谢您的帮助。

ajax google-sheets tabulator
1个回答
0
投票
    bldgChange: function () {
      console.log(this.selected)
      this.tabulator.parameter = this.selected
      fetch('<API-URL>?Building=' + this.selected)
        .then(response => response.json())
        .then(json => this.tabulator.setData(json.recordset))
    },

我放弃了ajaxURL,因为有太多人遇到问题而没有真正的解决方案。这是我为我需要的方法创建的方法。也许你可以根据自己的需要进行改造。

© www.soinside.com 2019 - 2024. All rights reserved.