如何在 ajax 调用的列中设置图标
How to set icon in column from ajax call
我试图在 table 首次呈现时更改显示在 ajax 调用的列中的图标。
如果我只有:
return "<i class='fas fa-eye fa-xs'></i>";
这是列设置
{title:"Review",formatter:reviewIcon, width:40, headerVertical:true, align:"center", cellClick:reviewCellClick },
我的 ajax 调用非常简单,也许不是最好的,但它得到了我想要的结果。
returned 值为 0 或其他值。我只关心 0.
var reviewIcon = function(cell, formatterParams, onRendered){ //plain text value
var cell = cell.getData();
var ag = cell.accessgroups;
var xhr = new XMLHttpRequest();
xhr.open("GET", "includes/getaccessgroups.php?ag="+ag, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var returned = xhr.response;
if(returned < 1 ){
return "<i class='fas fa-unlink fa-xs'></i>";
}
else {
return "<i class='fas fa-eye fa-xs'></i>";
}
}
}
xhr.send();
// return "<i class='fas fa-eye fa-xs'></i>";
};
基本上我希望它在 0 时显示未链接,在其他情况下显示眼睛。
如果return值为0,则显示fa-unlink
,否则显示fa-eye
。
非常感谢任何帮助。
恐怕你不能以这种方式做到这一点,Tabulator 中的格式化程序必须同步才能使 table 快速呈现 (否则 table 必须在它可以呈现每一行之前发出请求,这会使 table 在您滚动时非常卡顿).
这意味着格式化程序将在任何 ajax 请求 return 之前完成执行。正确的方法是在将数据加载到 table 之前用每行的正确值更新数据。
我试图在 table 首次呈现时更改显示在 ajax 调用的列中的图标。 如果我只有:
return "<i class='fas fa-eye fa-xs'></i>";
这是列设置
{title:"Review",formatter:reviewIcon, width:40, headerVertical:true, align:"center", cellClick:reviewCellClick },
我的 ajax 调用非常简单,也许不是最好的,但它得到了我想要的结果。 returned 值为 0 或其他值。我只关心 0.
var reviewIcon = function(cell, formatterParams, onRendered){ //plain text value
var cell = cell.getData();
var ag = cell.accessgroups;
var xhr = new XMLHttpRequest();
xhr.open("GET", "includes/getaccessgroups.php?ag="+ag, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var returned = xhr.response;
if(returned < 1 ){
return "<i class='fas fa-unlink fa-xs'></i>";
}
else {
return "<i class='fas fa-eye fa-xs'></i>";
}
}
}
xhr.send();
// return "<i class='fas fa-eye fa-xs'></i>";
};
基本上我希望它在 0 时显示未链接,在其他情况下显示眼睛。
如果return值为0,则显示fa-unlink
,否则显示fa-eye
。
非常感谢任何帮助。
恐怕你不能以这种方式做到这一点,Tabulator 中的格式化程序必须同步才能使 table 快速呈现 (否则 table 必须在它可以呈现每一行之前发出请求,这会使 table 在您滚动时非常卡顿).
这意味着格式化程序将在任何 ajax 请求 return 之前完成执行。正确的方法是在将数据加载到 table 之前用每行的正确值更新数据。