我正在尝试使用两个制表符表运行报表。一个主表,然后点击一行它将填充一个模态。所有的html部分都有效,而jquery(JS)也可以。我在ajax调用上有一个成功函数来设置模态中的数据。但似乎并没有等待ajax返回数据。见下面的代码。我可以在console.log中看到数据,因此console.log似乎正在运行它只是没有推送到表。如果我运行一个函数来从控制台手动设置数据,它的工作原理。所以不确定最新情况。
var CatVolumetable = new Tabulator("#myreport", {
//height:205, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
placeholder:"Select Year-Month to populate Data",
layout:"fitColumns", //fit columns to width of table (optional)
columns:[ //Define Table Columns
{title:"Category Name", field:"Category_name", align:"left"},
{title:"State", field:"State",align:"center"},
{title:"Max Quantity",field:"maxQuantity", align:"left"},
],
rowClick:function(e, row){ //trigger an alert message when the row is clicked
var state = row.getData().State;
//getStoresByState(state);
$('#drilldown').modal('toggle');
let myUrl = 'http://localhost:3000/view_state_category_volume_drilldown/'+state;
$.ajax({
//$.ajax({
url: myUrl,
method: 'get',
dataType: 'json',
success: function(data){
console.log(data);
ddtable.setData(data);
}
});
var ddtable = new Tabulator("#drilldownTable", {
//height:205, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
//ajaxURL:""
placeholder:"No Data Available",
layout:"fitColumns", //fit columns to width of table (optional)
columns:[ //Define Table Columns
{title:"Manager_email", field:"Manager_email"},
{title:"Manager_name", field:"Manager_name", align:"left"},
{title:"Store_num", field:"Store_num"},
{title:"Street_address", field:"Street_address", align:"center"},
{title:"City Name", field:"City_name", align:"center"},
],
});
解决方案:我发现问题是在切换模态后(即在模态可见之后)必须加载数据。如果我在show事件监听器上加载数据,它可以很好地工作。下面是带bootstrap的代码。
$("#drilldown").on('shown.bs.modal', function (e){
///Ajax call with success handler to load data
})
如果API对于您的第二个制表表来说太快了
检查此post。使用以下代码在drilldownTable初始化后设置数据
if ($("#drilldownTable").hasClass("tabulator")){
//element has class of .tabulator
}