Datatable is not refreshing in ASP.NET MVC4 Project

Datatable is not refreshing in ASP.NET MVC4 Project

prasenjit_basuprasenjit_basu Posts: 1Questions: 0Answers: 0

Hi,
I have looked into so many answer to same problem but its not working. The DataTable works as per in the first data load. But when I modify the parameter to reload with different data the new data is appending to old data. I have set the iDisplayLength=5 when I refresh the data the number of row is 8(3 old+5 new). Please help me in unravel the mystery.

JAVASCRIPTS CODE:

$("#btnCheck").click(function () {
var startDate = $("#txtStartDate").val();
var endDate = $("#txtEndDate").val();
var applName = $("#ddlApplLst").val();
var servLevel = $("#ddlErrServlbl").val();
if (evntDatatable != null) {
$('#EvntGrd').dataTable().fnClearTable();
}
LoadEventGrd(startDate, endDate, applName, servLevel);
});

        function LoadEventGrd(stdate, endate, applname, servlbl) {
            evntDatatable = $('#EvntGrd').dataTable({
                "bServerSide": true,
                "bDestroy": true,
                "sAjaxSource": '@Url.Action("RefreshEventData", "Home")',
                "bProcessing": true,
                "iDisplayLength": 5,
                "bPaginate": true,
                "bLengthChange": false,
                "bFilter": false,
                "bSort": true,
                "bInfo": true,
                "bAutoWidth": false,
                "fnServerData": function (sSource, aoData, fnCallback) {
                    aoData.push({ "name": "StDate", "value": stdate }
                        , { "name": "EnDate", "value": endate }
                        , { "name": "ApplName", "value": applname }
                        , { "name": "Sevrlbl", "value": servlbl }
                        );
                    $.getJSON(sSource, aoData, function (json) {
                        fnCallback(json)
                    });
                }
            });

}

SERVER SIDE CODE:

public JsonResult RefreshEventData(JQueryDataTableParamModel param, string StDate, string EnDate, string ApplName, Values.SeverityLevel Sevrlbl)
{
EventSearch objEvntSrc = new EventSearch();
objEvntSrc.ApplicationName = ApplName;
objEvntSrc.SeverityLevel = Sevrlbl;
objEvntSrc.StarDate = StDate;
objEvntSrc.EndDate = EnDate;
objEvntSrc.SortColName = GetSortedColumnName(param.iSortCol_0);
objEvntSrc.OrdDirection = Values.GetSortOrderDirection(param.sSortDir_0);
var lstEvnt = EventManager.GetAllEventDetails(objEvntSrc, param.iDisplayStart, param.iDisplayLength);
int Count = lstEvnt.Count;
var totalRowsCount = Count;
var filteredRowsCount = param.iDisplayLength;
var aaData = lstEvnt.Entities.Select(d => new string[]
{
d.EventDate
,d.Severity
,d.Message
,d.ExceptionName
,d.ClassName
,d.OperationName
,d.AssemblyName
,d.MachineName
,d.UserName
,d.Alert
,d.AlterID.ToString()
}).ToArray();

        return Json(new
        {
            sEcho = param.sEcho,
            aaData = aaData,
            iTotalRecords = Count,
            iTotalDisplayRecords = Count
        }, JsonRequestBehavior.AllowGet);

}

This discussion has been closed.