{hero}

row().child().remove()

起始版本:DataTables 1.10.1

刪除所選父資料列的子資料列。

說明

此方法用於從父資料列移除子資料列,將其從顯示的表格中移除 (如果它們目前正在顯示),並釋放為這些資料列配置的記憶體。

請注意,此方法僅在呼叫 row().child() 並設定參數時才可用。這是因為在沒有參數的情況下呼叫 row().child() 將會回傳子資料列,其為 jQuery 物件或 undefined。當使用參數呼叫時,row().child() 會回傳一個 DataTables.Api 實例。如果需要在不設定任何參數的情況下顯示子資料列,請使用 row().child.show()

與許多其他操作 DataTable 的方法不同,此方法不需要在之後立即呼叫 draw()。子資料列會從表格中移除,而不需要 DataTables 重新繪製。

類型

function row().child().remove()

說明

從顯示中移除子資料列並釋放任何配置的記憶體

回傳

DataTables API 實例。

範例

根據目前的狀態顯示/隱藏資料列,並根據需要新增資料列內容。

var table = new DataTable('#myTable');

$('#example tbody').on('click', 'td.details-control', function () {
	var tr = $(this).parents('tr');
	var row = table.row(tr);

	if (row.child.isShown()) {
		// This row is already open - remove it
		row.child(false).remove();
		tr.removeClass('shown');
	}
	else {
		// Open this row (the format() function would return the data to be shown)
		row.child(format(row.data())).show();
		tr.addClass('shown');
	}
});