9

我正在使用 Jquery UI DataTable,它在select(DropDown) change事件中填充。PageLoad就可以了。当我执行dropdown change事件时,DataTableReinitialized通过使用fnDestroy(),但格式发生了DataTable变化。下面是我的代码..

  campusChangeEvent = function () {
        $('#cmbClassCP').on('change', function () {
        $('#ClassRegistredDataTable').dataTable().fnDestroy();
            GetAllClassbyCampus($('#cmbClassCP :selected').val());
        });
    }, 

 GetAllClassbyCampus = function (id) {
        var oTable = $('#ClassRegistredDataTable').dataTable({
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "bServerSide": true,
            "bRetrieve": true,
            "bDestroy": true,
            "sAjaxSource": "/forms/Setup/Setup.aspx/GetAllClassBycampus?CampusId=" + id,
            "fnServerData": function (sSource, aoData, fnCallback) {
                $.ajax({
                    "type": "GET",
                    "dataType": 'json',
                    "contentType": "application/json; charset=utf-8",
                    "url": sSource,
                    "data": aoData,
                    "success": function (data) {
                        fnCallback(data.d);
                    }
                });
            },
            "aoColumns": [
                         {
                             "mDataProp": "RowNo",
                             "bSearchable": false,
                             "bSortable": false,
                             "sWidth": "20"
                         },
                        {
                            "mDataProp": "CampusName",
                            "bSearchable": false,
                            "bSortable": false,

                        },
                        {
                            "mDataProp": "ClassName",
                            "bSearchable": true,
                            "bSortable": false

                        },
                        {
                            "mDataProp": "Section",
                            "bSearchable": false,
                            "bSortable": false
                        },
                        {
                            "mDataProp": "Description",
                            "bSearchable": false,
                            "bSortable": false
                        },
                        {
                            "mData": null,
                            "bSearchable": false,
                            "bSortable": false,
                            "fnRender": function (oObj) {
                                return '<a class="edit" href="">Edit</a>';

                            }
                        }
            ]
        });

我的表格看起来Page Load像..

在此处输入图像描述

更改事件后DropDown,如下所示..

在此处输入图像描述

任何帮助....

4

3 回答 3

10

我是用这种方法做到的。。

 $('#ClassRegistredDataTable').dataTable().fnDestroy();

这将覆盖jquery.dataTables.cssdataTablecss

默认情况下,它看起来像

table.dataTable {
    margin: 0 auto;
    clear: both;
    width: 100%;
}

改成..

table.dataTable {
    margin: 0 auto;
    clear: both;
    width: 100% !important;
}

它对我有用..

于 2013-09-17T08:03:17.280 回答
2

尝试:

$('#ClassRegistredDataTable').dataTable().fnDraw();

或者:

//if you don't want the table reorder/resorted
$('#ClassRegistredDataTable').dataTable().fnDraw(false);
于 2013-09-07T06:53:59.843 回答
1

即使你需要清理你的桌子,像这样:

$('#ClassRegistredDataTable tbody').html('');
$('#ClassRegistredDataTable').dataTable().fnDestroy();
于 2013-12-06T06:19:49.337 回答