我想要做的是从ajax数据设置“column”属性
json 数据具有“data”和“columns”属性,因此要提取数据,我需要这样的东西。
primaryTable = $('#example').DataTable({
"ajax": "data.txt"
});
假设 txt 文件有一个列属性,可以定义列 {"data":"Name"} 等,有没有办法可以引用它?
primaryTable = $('#example').DataTable({
"ajax": "data.txt"
"columns" : data.columns
});
有什么办法可以引用吗? 另一种方法是使用 jQuery.ajax 或 getJSON,我已经使用过它们,但无法弄清楚如何正确加载数据。
谢谢
最佳答案
看起来(至少截至 2013 年 11 月),使用单个 AJAX 调用是不可能完成的。 Source
The answer is no - I'm sorry to say you cannot do that in DataTables at this time. The full range of options that are available in aoColumns cannot be represented in JSON (specifically functions) so there is no method for this in DataTables at this time. I might relax that in future, but at the moment you'll need to make an Ajax request to get the column information yourself. Allan
您可以通过发出两个连续的 AJAX 调用来解决该问题:第一个用于获取数据以填充表标题列,第二个用于数据本身。
该链接还提供了示例调用。
关于javascript - DataTables.Net - 有没有办法从数据中设置属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26372469/