【问题标题】:Change placeholder text after table has loaded. Hence, two values for placeholder text加载表格后更改占位符文本。因此,占位符文本的两个值
【发布时间】:2021-02-11 05:09:34
【问题描述】:

如何在表格加载后更改占位符文本?没有 jQuery。

理想的步骤:

  1. 表加载。没有数据。占位符说:“正在获取数据”
  2. 使用以下方式获取 JSON 数据:
// Script
const getJSON = async url => {
    try {
        const response = await fetch(url);
        if(!response.ok) 
        throw new Error(response.statusText);
        const data = await response.json();
        return data; 
    } catch(error) {
        return error;
    }
};
// HTML
var table = new Tabulator("#example", {
    ajaxLoader: false,
    data:JSONdata,
    ...
    ...
}
getJSON('https://...').then(JSONdata => {
            table.replaceData(JSONdata);
        }).catch(error => {
            console.error(error);
});
  1. 占位符文本更改为:“未找到结果。”

附注当 JSON 失败或未找到搜索结果时,此功能很重要。我添加了一个只显示匹配行的搜索功能。

【问题讨论】:

    标签: tabulator


    【解决方案1】:
    table.options.placeholder.firstElementChild.textContent = 'No results found.';
    

    可能应该在getJSON.then() 块中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-28
      • 2017-03-31
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多