I'm trying to make use of both the ajaxResponse and setData for a Tabulator 5.0 table. Somewhere my URL parameters are getting lost. In the following code the value for params is and empty object when logged to the console.
I'm using ajaxResponse because the portion of the response I need is in the "results". And I'm using setData because my intention is to repeatedly call it dynamically as my parameters change.
var table = new Tabulator("#my-tabulator-table", {
ajaxResponse:function(url, params, response){
console.log(url);
console.log(params);
return response.results;
},
});
var columns = [
{title:"id", field:"id", headerFilter:false, visible:true, download:true},
{title:"field1", field:"field1", headerFilter:true, visible:true, download:true},
{title:"field2", field:"field2", headerFilter:true, visible:true, download:true},
{title:"field3", field:"field3", headerFilter:true, visible:true, download:true},
];
var url = "/api/v1/myendpoint";
var params = {"param_name": "abc"};
table.on("tableBuilt", function(){
table.setColumns(columns);
table.setData(url, params);
});
So how can I pass "params" so that they are combined with the url to make the proper ajax query call?
If you are looking to make this request to load the initial data in the table then there is no need to call these functions at all, you can use the ajaxURL and ajaxParams options in the table constructor to automatically trigger the initial ajax request when the table loads
var table = new Tabulator("#example-table", {
ajaxURL:"/api/v1/myendpoint, //ajax URL
ajaxParams: {"param_name": "abc"},
});
You can also pass in your columns in a similar way using the columns option:
var table = new Tabulator("#example-table", {
columns:[
{title:"Name", field:"name", sorter:"string", width:200, editor:true},
{title:"Age", field:"age", sorter:"number", hozAlign:"right", formatter:"progress"},
],
});
If you are looking to call the setData function at a later point, then you are calling it correctly in your example. There was a bug in the initial 5.0 release that prevented parameters being correctly set through the setData function, but that has been resolved in a sebsequent patch release.