簡體   English   中英

使用datatables jquery將數據插入特定的列單元格

[英]insert data into specific column cell using datatables jquery

我在這里搜索了數據表的文檔,以了解如何將數據添加到表中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");
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM