Recently, I have started getting an issue related to "SystemOutOfMemoryException" in free-jQgrid. The version that I am using is 4.15.4 with MVC 5 and Sql Server DB queries for bringing data . The reason I have found is growth of the data. If data is around 10K with LoadOnce:true
at that point it works without any issue. But when more data comes then it started throwing this issue.
I am getting all data from database in one go and loads it to the grid.
Here is some pieces of controller code:
public JsonResult GetDataWRTLanguage(string searchKey)
{
FormBL formsbl = new FormBL();
List<Form_Check> lstPPVM = new List<Form_Check>();
filter f = new filter();
string returnedLangCode = "";
if (searchKey != "")
{
TempData["LanguageCode"] = searchKey;
}
if (Convert.ToString(TempData["LanguageCode"]) != "")
{
returnedLangCode = Convert.ToString(TempData["LanguageCode"]);
TempData.Keep("LanguageCode");
}
else{
returnedLangCode = searchKey;
}
lstPPVM = formsbl.getDataWithLanguage(returnedLangCode);
//var newList = JsonConvert.SerializeObject(lstPPVM);
int page = 1, rows = 1;
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = lstPPVM.Count();
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
var Results = lstPPVM.AsQueryable();
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = Results
};
var jsonResult = Json(jsonData, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
Here is jqgrid code
$("#grid").jqGrid({
url: '/MView/GetDataWRTLanguage?searchKey=' + LanguageId + "",
mtype: "GET",
datatype: "json",
colNames: [*more than 15*]
colModel: [*body of all columns with search*]
loadComplete: function () {
if ($('#grid').getGridParam('records') === 0) {
oldGrid = $('#GridIdb2 tbody').html();
$(".jqgfirstrow").css("height", "1px");
}
else {
oldGrid = "";
}
this.p.lastSelected = lastSelected;
var obj = JSON.parse(sessionStorage.getItem('majorgridInfo'));
if (obj != undefined || obj != undefined || obj != null || obj != null) {
jQuery("#grid").setGridParam({ rowNum: obj.rowNum.toString() });
var grid = $("#grid");
jQuery("#grid").setGridParam({ rowNum: obj.rowNum }).trigger("reloadGrid");
$('.ui-pg-selbox').val(obj.rowNum);
}
},
onPaging: function (pgbtn) {
Selected_RowList = $('.ui-pg-selbox').val();
saveGridParameters();
},
forceClientSorting: true,
cmTemplate: { autoResizable: true },
width: '100%',
scrollbar: true,
autoResizing: { compact: true },
editurl: "/MajorsView/EditParticipantRecords/",
pager: jQuery('#pager'),
loadonce: true,
viewrecords: true,
gridview: true,
height: '480px',
//width: '100%',
//maxHeight: 980,
//pager: '#pager',
rowNum: 25, //// adjust height of Jqgrid
rowList: [25, 100, 200, 500, 1000,10000], ////adjust height of Jqgrid
ignoreCase: true,
autowidth: true,
shrinkToFit: false,
hidegrid: true, //To disable collapsing
iconSet: "fontAwesome",
caption: "<i class='fa fa-users'></i> Participant List",
multiSort: true,
sortname: 'ReferenceId',
sortOrder: 'asc',
rowattr: function (rd) {
if (rd.Check === "true") {
return { "class": "state_inactive" };
}
},
multiselect: false,
emptyrecords: "No records to display",
jsonReader:
{
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
Id: "ReferenceId"
},
inlineEditing: { keys: true, defaultFocusField: "ReferenceId", focusField: "ReferenceId" },
});
Here I also used JsonMaxLength property but it still throws error. I've seen that even 60K data is still working fine with it but for me it starts giving error on more than 10K data.
Additional questions: Should I use Server side jqgrid implementation, if yes then how can i modify this link to newer version of MVC and jQgrid version.
Any help would be greatly appreciated.