Refresh Datatable

Refresh Datatable

ramyatramyat Posts: 1Questions: 0Answers: 0
edited July 2013 in DataTables 1.9
Hi,

I have an issue on refreshing datatables. I used fnClearTable() to clear the datatable but it didn't work.

Basically I have two dropdowns with values and two buttons "Search" and "Reset". When 2 dropdown values are selected and hit "Search" button it displays datatable with data/records. Now when I hit "Reset" button it supposed to clear the values in the dropdown as well as the datatable. The datatable should pretty much be empty with no records but with just column names. Here is the code, and I am using Jquery datatables 1.9.4.

//buttons





//datatable

Search Results



// Search func
function searchClick(){

if (!isValidNonEmptyGuid($("#ContractID").val())) {
alert("Please select a Contract.");
return;
}
else if (!isValidNonEmptyGuid($("#ServiceLevelID").val())) {
alert("Please select a Proposed Service Level.");
return;
}
rebindGrid()
}

//Datatable initialization
jQuery(document).ready(function ($) {
var dataTable = LAMP.BaseDataTable.extend({
tableId: '@Model.ReportTableId',
additionalParams : function () {
return {
'contractID': $('#ContractID').val(),
'proposedServiceLevelID': $('#ServiceLevelID').val(),
'currentServiceLevelID': $('#AddServiceLevelID').val()
};
},
exportUrl: '@Url.Action("__GridDataCSV", "ContractCostAnalysis", new { area = "Reports" })',
baseUrl: '@Url.Content("~/")',
buttons: [
'columns',
'export',
]
}, {
"aoColumns": @Html.Raw(Model.ColumnSettings),
"sAjaxSource": "@Url.Content("~/Reports/ContractCostAnalysis/__GridData")",
"bServerSide": true,
"sScrollY": "300px",
});
LAMP.Report.LAMPDataTable = dataTable;
});

//Rebind Grid func
function rebindGrid() {
var table = $('#@Model.ReportTableId').dataTable();
table.fnReloadAjax();
}

//Reset func
function resetSearch() {
$("#ContractID").val("");
$("#ServiceLevelID").val("");

var oTable = $('#@Model.ReportTableId').dataTable();
oTable.fnClearTable();
}

Please take a look and let me know if I have gone wrong somewhere in the code.

Thanks in Advance !!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    fnClearTable is a client-side function. You are using server-side processing ( "bServerSide": true, ) so the data is at the server. If you want to clear the data, you need to do so at the server and then redraw the table (fnDraw). DataTables doesn't know anything about your server-side environment, so it wouldn't be able to clear the data there.

    Allan
This discussion has been closed.