我正在使用Jquery UI DataTable,它填充在select(DropDown)
change
事件中。
在PageLoad
可以。当我执行dropdown change
事件时,DataTable
使用Reinitialized
为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
更改事件后,如下所示..
任何帮助......
答案 0 :(得分:10)
我用这种方法做到了..
$('#ClassRegistredDataTable').dataTable().fnDestroy();
这将覆盖 jquery.dataTables.css
中 dataTable 的 css默认情况下,它看起来像
table.dataTable {
margin: 0 auto;
clear: both;
width: 100%;
}
将其更改为..
table.dataTable {
margin: 0 auto;
clear: both;
width: 100% !important;
}
它对我有用..
答案 1 :(得分:2)
尝试:
$('#ClassRegistredDataTable').dataTable().fnDraw();
或:
//if you don't want the table reorder/resorted
$('#ClassRegistredDataTable').dataTable().fnDraw(false);
答案 2 :(得分:1)
即使您需要清理表格,例如:
$('#ClassRegistredDataTable tbody').html('');
$('#ClassRegistredDataTable').dataTable().fnDestroy();