两者均能对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("<b>+</b>");
        }
    });

    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("<b>+</b>");
        }
        else {
            // Open this row
            row.child(format(row.data())).show();
            tr.addClass('shown');
            tr.children("td").eq(0).html("<b>-</b>");
        }
    });
}

function format(row) {
    return "<div style=\"padding-left:50px;\"><b>标题:</b>" + row.Subject +" <b>内容:</b>"+ row.Body+"</div>";
}
<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>

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐