如何向jQuery DataTables插件添加自定义行

时间:2012-05-24 16:48:43

标签: jquery ajax jquery-datatables

我有一个基本的html页面,上面有一个jQuery DataTables网格。 我能够

http://datatables.net/index

它在浏览器中显示就好了。问题是我想为每个部分添加自定义行标题。因此行标题可以位于第3行,第8行......等。如何在数据表的中间动态插入行标题?

getDataOverview: function ($page) {
        $page.find('#tblDataTable').dataTable({
            "bServerSide": true,
            "fnDrawCallback": onAfterTableLoad,
            "bJQueryUI": false,
            "bFilter": false,
            "bPaginate": false,
            "bLengthChange": false,
            "oLanguage": { "sInfo": "" },
            "sAjaxSource": this.getUrl($page) + '/GetDataOverview/',
            "fnServerData": function (sSource, aoData, fnCallback) {

                $.ajax({
                    dataType: 'json',
                    type: "POST",
                    url: sSource,
                    data: aoData,
                    success: fnCallback,
                    error: function (jqXHR, textStatus, errorThrown) { alert('Error getting data' + errorThrown) }
                })
            },
            "bProcessing": false, // don't want to use the default progress indicator at this time
            "aoColumnDefs": [
                { "sName": "ID", "aTargets": [0], "mDataProp": "ID", "bSortable": false },
                { "sName": "Name", "aTargets": [1], "mDataProp": "Name", "bSortable": false },
                { "sName": "Other", "aTargets": [2], "mDataProp": "Other", "bSortable": false }
            ],
            "aaSorting": [[0, "asc"]] // default sort by Task Type
        });
    },

1 个答案:

答案 0 :(得分:1)

结帐fnRowCallback。在回调期间,您可以确定要添加标题的行,然后在符合条件的情况下注入新行。