gpt4 book ai didi

javascript - DataTables:使用 JQuery 更改所选单元格的值

转载 作者:行者123 更新时间:2023-12-01 00:49:27 25 4
gpt4 key购买 nike

我有一个从数据库填充的数据表。我想更改所选单元格的值。

我不知道如何使用单元格和行索引更改单元格的值。我怎样才能做到这一点?

这就是我所拥有的:

  $('#dtBasicExample').on('click', 'tbody td', function() {

var table = $('#dtBasicExample').DataTable();

//Content I want to insert i the cell
var NewValue= 'NewValue';

//get cell index
var CellIndex=table.cell( this ).index().columnVisible;

//get row index
var RowIndex= table.cell( this ).index().row;
})

最佳答案

要更改单元格中的数据,您需要 DataTables API 中的 cell().data() 函数:https://datatables.net/reference/api/cell().data()

$(document).ready(function() {
var table = $('#example').DataTable();
$('#example tbody').on('click', 'td', function() {
var colIndex = table.cell(this).index().column;
var rowIndex = table.cell(this).index().row;
table.cell(rowIndex, colIndex).data("new")
});
});

更简单的方法:

$(document).ready(function() {
var table = $('#example').DataTable();
$('#example tbody').on('click', 'td', function() {
table.cell(this).data("new");
});
});

关于javascript - DataTables:使用 JQuery 更改所选单元格的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57103672/

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