layui table 刪除一行 或多行
阿新 • • 發佈:2019-01-28
1.layui 刪除一行 或多行 例項程式碼;(這個是刪除表名的行資料,後臺並沒有刪除,自己去實現很好實現的喲)
var DeleteData = []; var FilterArray = function (DataIndex) { DeleteData = filter_array(DeleteData); for (var i = 0; i < DeleteData.length; i++) { if (DeleteData[i] == DataIndex) { delete DeleteData[i]; } DeleteData = filter_array(DeleteData); } return DeleteData; } function filter_array(array) { return array.filter(item => item); }
//單擊行勾選checkbox事件 $(document).on("click", ".layui-table-body table.layui-table tbody tr", function () { var index = $(this).attr('data-index'); var tableBox = $(this).parents('.layui-table-box'); //存在固定列 if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length > 0) { tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l"); } else { tableDiv = tableBox.find(".layui-table-body.layui-table-main"); } var CheckLength = tableDiv.find("tr[data-index=" + index + "]").find( "td div.layui-form-checked").length; //刪除的程式碼如下 if (CheckLength == 0) { DeleteData.push(index); } else { FilterArray(index); } /// var checkCell = tableDiv.find("tr[data-index=" + index + "]").find( "td div.laytable-cell-checkbox div.layui-form-checkbox I"); if (checkCell.length > 0) { checkCell.click(); } }); $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) { e.stopPropagation(); });
//無重新整理刪除
for (var i = 0; i < DeleteData.length; i++) {
$("tr[data-index='" + DeleteData[i] + "']").remove();
}
掃一掃 謝謝