两者均能对dataTable进行初始化,DataTable() 没有.fnDraw(false)函数,dataTable()没有.row(tr)函数。
function fnClickReload() { if (typeof (tblList) != "undefined") { tblList.fnDraw(false); editRow(); } }
如果dataTable()要使用.row(tr)函数,使用.api()
var tr = $(this).closest(\'tr\'); var row = tblList.api().row(tr);
例如:
var tblList; function getList() { if (typeof (tblList) != "undefined") { tblList.fnClearTable(false); tblList.fnDestroy(); } tblList = $("#tblList").dataTable({ columns: [ { orderable: false, defaultContent: "", className: \'details-control\', data: \'MessageId\' }], fnCreatedRow: function (nRow, aData, iDataIndex) { $(\'td:eq(0)\', nRow).html("+"); } }); editRow(); } function editRow() { $(\'#tblList tbody\').on(\'click\', \'td.details-control\', function () { var tr = $(this).closest(\'tr\'); var row = tblList.api().row(tr); if (row.child.isShown()) { // This row is already open - close it row.child.hide(); tr.removeClass(\'shown\'); tr.children("td").eq(0).html("+"); } else { // Open this row row.child(format(row.data())).show(); tr.addClass(\'shown\'); tr.children("td").eq(0).html("-"); } }); } function format(row) { return "标题:" + row.Subject +" 内容:"+ row.Body+""; }
<table class="table table-striped table-bordered table-hover " id="tblList"> <thead> <tr> <th>th> <th>发送机构th> <th>提醒类别th> <th>提醒时间th> <th>提醒范围th> <th>提醒机构th> @*<th>提醒标题th> <th>提醒内容th>*@ <th>状态th> <th>创建者th> tr> thead> <tfoot> <tr> <th>th> <th>发送机构th> <th>提醒类别th> <th>提醒时间th> <th>提醒范围th> <th>提醒机构th> @*<th>提醒标题th> <th>提醒内容th>*@ <th>状态th> <th>创建者th> tr> tfoot> table>