我已经尝试了几天,却不知道如何将Google表格文档加载到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");
不幸的是,我无法弄清楚自己在做什么错。 预先感谢您的帮助。
答案 0 :(得分: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,因为太多人对此有疑问,没有真正的解决方案。这是我根据需要创建的方法。也许您可以根据需要进行改造。