Clearing data tables

Clearing data tables

ambesangevishalambesangevishal Posts: 4Questions: 0Answers: 0
edited February 2014 in General
I am using data tables in my application. We have a form with search criteria and search results on same page. I am using data table to display search results. I am also using fnReloadAjax plug in to display modified search results without reloading page. Initial loading of table is working fine.I am able to clear data table on Click of clear search criteria button as well. Problem I am facing is when data table is cleared, sorting for column is displayed as per setting applied initially. I wan to clear sorting for columns once data table is cleared on click of Clear Search criteria.
Below is my data table Definition.

oTable = $("#dataTables")
.dataTable(
{
"sDom" : "ptpr",
"iDisplayLength" : iDisplayLength,
"iDisplayStart" : 0,
"bAutoWidth" : true,
"bProcessing" : true,
"bServerSide" : true,
"sPaginationType" : "full_numbers",
"sAjaxSource" : "SearchMDR?userAction=refresh",
"fnDrawCallback" : function(
oSettings) {

if (oSettings.fnRecordsTotal() == 0) {

$("#btnDownloadMdr1").attr(
"disabled",
"disabled");
$("#btnDownloadMdr2").attr(
"disabled",
"disabled");
} else {
$("#btnDownloadMdr1")
.removeAttr(
"disabled");
$("#btnDownloadMdr2")
.removeAttr(
"disabled");
}
$('#iDisplayStart')
.val(
this
.fnPagingInfo().iStart);
$('#iDisplayLength')
.val(
this
.fnPagingInfo().iLength);

$('#sSortDir_0')
.val(
oSettings.aaSorting[0][1]);
$('#iSortCol_0')
.val(
oSettings.aaSorting[0][0]);

},
"fnServerData" : function(sSource,
aoData, fnCallback,
oSettings) {

if (!isClearSearchCriteria) {
oSettings.jqXHR = $
.ajax({
"dataType" : 'json',
"type" : "POST",
"url" : sSource,
"data" : aoData,
"success" : function(
json) {

if (json.errorMsg == null
|| json.errorMsg == ''
|| json.errorMsg == "undefined") {
fnCallback(json);
} else {
document
.getElementById('displayErrorMessage').innerHTML = json.errorMsg;
document
.getElementById("displayErrorMessage").style.display = "block";
fnCallback(json);
}
},
"error" : function(
xhr,
status,
error) {

$(
'#displayErrorMessage')
.html(
"Error occured while executing Search, Please contact JDCP Support Team.");
$(
'#displayErrorMessage')
.show(
0);
}
});
} else {

isClearSearchCriteria = false;
clearCriteria();
var data = $
.parseJSON('{"iTotalRecords":0,"iTotalDisplayRecords":0,"errorMsg":null,"aaSorting" : [[]],"aaData":[]}');
fnCallback(data);
}
},
"oLanguage" : {
"sProcessing" : "",
"sEmptyTable" : "No matches found for the given search criteria. Please search again",
"sZeroRecords" : "No matches found for the given search criteria. Please search again",
"oPaginate" : {
"sFirst" : "",
"sNext" : "",
"sPrevious" : "",
"sLast" : ""
}
},
"aoColumns" : [ {
"mData" : "mdrName"
}, {
"mData" : "plannedReleasedDate"
}, {
"mData" : "description"
}, {
"mData" : "componentModelNo"
}, {
"mData" : "sdaName"
}, {
"mData" : "createdBy"
}, {
"mData" : "divisionName"
}, {
"mData" : "mdrStatus"
}, {
"mData" : "mdrControllers"
}, {
"mData" : "percentComplete"
}, {
"mData" : "noOfPins"
}, {
"mData" : "noOfRmtCapPins"
}

],
"aoColumnDefs" : [
{
"aTargets" : [ 0 ],
"bSortable" : true,
"sWidth" : "120px",
"mRender" : function(
data, type,
full) {
return ' '
+ data
+ '';
}
},
{
"aTargets" : [ 1 ],
"bSortable" : false,
"mRender" : function(
data, type,
full) {

var returnVal = '-';
if (data != null) {

returnVal = data;
}
return returnVal;
}
},
{
"aTargets" : [ 2 ],
"bSortable" : false,
"mRender" : function(
data, type,
full) {

var returnVal = '-';
if (data != null) {

returnVal = data;
}
return returnVal;
}
},
{
"aTargets" : [ 3 ],
"bSortable" : false,
"mRender" : function(
data, type,
full) {

var returnVal = '-';
if (data != null) {

returnVal = data;
}
return returnVal;
}
},
{
"aTargets" : [ 4 ],
"bSortable" : true,
"mRender" : function(
data, type,
full) {

var returnVal = '-';
if (data != null) {

returnVal = data;
}
return returnVal;
}
},
{
"aTargets" : [ 5 ],
"bSortable" : false,
"mRender" : function(
data, type,
full) {

var returnVal = '-';
if (data != null) {

returnVal = data;
}
return returnVal;
}
},
{
"aTargets" : [ 6 ],
"bSortable" : false,
"mRender" : function(
data, type,
full) {

return replaceHTMLSpecialCharacters(data);
}
},
{
"aTargets" : [ 7 ],
"bSortable" : false,
"mRender" : function(
data, type,
full) {

var returnVal = '-';
if (data != null) {

returnVal = data;
}
return returnVal;
}
},
{
"aTargets" : [ 8 ],
"bSortable" : false,
"mRender" : function(
data, type,
full) {
var controllers = '';
for ( var i = 0; i < data.length; i++) {
controllers += data[i]
+ '';
}

return controllers;
}
}, {
"aTargets" : [ 9 ],
"bSortable" : false
}, {
"aTargets" : [ 10 ],
"bSortable" : false
}, {
"aTargets" : [ 11 ],
"bSortable" : false
} ],
"aaSorting" : [ [ 0, 'desc' ] ]
});

Your help is appriciated.

Thanks in advance.
This discussion has been closed.