gpt4 book ai didi

javascript - 使用数据表 jquery 将数据插入特定列单元格

转载 作者:行者123 更新时间:2023-11-28 07:49:13 24 4
gpt4 key购买 nike

我已经搜索了数据表的文档,了解如何将数据添加到此处的表中 https://datatables.net/examples/data_sources/index.html但我找不到将数据插入给定列的单个单元格的方法。例如,我需要这样的东西:

 "columns": [ {target (0), "value which will be inserted"} ]

有一种方法可以从数组中插入数据,但数组的每个部分都包含整行的值(请参见此处 https://datatables.net/examples/data_sources/js_array.html ),但我需要将数据插入到与列相关的不同单元格中,因为我不这样做最初不知道列标签。这是因为数据将采用 json 格式,首先我需要提取每个 json 对象的唯一日期。这些将是我的列标题。然后,对于每个基于其日期的对象,我需要将其放入相关的日期列中。所以逻辑应该是这样的:

 if this date column (from the table) == json object date then put it there

谢谢

最佳答案

经过大量研究后,似乎 DataTables 中不提供此功能。这就是为什么我用 jQuery 解决了这个问题。使用下面的代码,我可以迭代列并在其中插入值。

//change 1 to the column at hand
$("#table tr > :nth-child(1)").each(function(index) {
//skip the column header
if (index > 0){
//insert value
$(this).html("<span class='fixed-size-square'> value to be inserted");
}
});

关于javascript - 使用数据表 jquery 将数据插入特定列单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27063225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com