如何删除当前行与jQuery插件数据表
-
20-09-2019 - |
题
我有在我使用jQuery数据表插件的表按钮的一列。按钮说,“删除”和想法是,当你点击该按钮将删除当前行中的表格。
当我打电话fnDeleteRow
它似乎工作第一次,但没有任何进一步的时间,该行因此它看起来像它不是一个真正正确地删除该行。
解决方案
尝试这种情况:
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));
如果它不工作,检查下列示例
其他提示
让我们说你附加的功能,当用户点击该按钮被调用。该函数将是这样的
function DeleteRow(event)
{
//get the row of the cell that is clicked
var $row = $(this).parents("tr").eq(0)
//if you need the id you can get it as
var rowid = $row.attr("id");
//now you can call delete function on this row
$row.delete();
}
这样如何:
// Delete Row
$('.glyphicon-minus').on("click", function() {
configTable.row($(this).closest("tr").get(0)).remove().draw();
});
这此页面:
$('#example tbody td').click( function () {
/* Get the position of the current data from the node */
var aPos = oTable.fnGetPosition( this );
//...
} );
这是怎么对我的作品。在文件准备功能我HTML表的转换后的版本分配给一个变量和一个按钮被点击时,我通过使用jQuery家长/孩子的并发送你作为参数传递给图书馆的fnDeleteRow()函数的行。
下面是从库函数的意见。而这在库中提到的例子。
/**
* Remove a row for the table
* @param {mixed} target The index of the row from aoData to be deleted, or
* the TR element you want to delete
* @param {function|null} [callBack] Callback function
* @param {bool} [redraw=true] Redraw the table or not
* @returns {array} The row that was deleted
* @dtopt API
* @deprecated Since v1.10
*
* @example
* $(document).ready(function() {
* var oTable = $('#example').dataTable();
*
* // Immediately remove the first row
* oTable.fnDeleteRow( 0 );
* } );
*/
// And here's how it worked for me.
var oTable;
$("document").ready(function () {
oTable = $("#myTable").dataTable();
});
//Remove/Delete button's click.
$("a[name='deleteColumn']").click(function () {
var $row = $(this).parent().parent();
oTable.fnDeleteRow($row);
});
不隶属于 StackOverflow