i am using Jquery UI DataTable, which is filled on select(DropDown)
change
event.
On PageLoad
its ok. When i perform dropdown change
event, DataTable
is Reinitialized
by using fnDestroy()
, but the format of DataTable
changes. Below is my code..
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>';
}
}
]
});
My form looks on Page Load
like..
After DropDown
change event, looks like below..
Any Help....
i have done it by this method..
$('#ClassRegistredDataTable').dataTable().fnDestroy();
This will override css of dataTable in jquery.dataTables.css
By Default it looks like
table.dataTable {
margin: 0 auto;
clear: both;
width: 100%;
}
change it to..
table.dataTable {
margin: 0 auto;
clear: both;
width: 100% !important;
}
It worked for me..
try:
$('#ClassRegistredDataTable').dataTable().fnDraw();
or:
//if you don't want the table reorder/resorted
$('#ClassRegistredDataTable').dataTable().fnDraw(false);
Even you require to clear your table, like this:
$('#ClassRegistredDataTable tbody').html('');
$('#ClassRegistredDataTable').dataTable().fnDestroy();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With