MVC5 Entity Framework Server Side
MVC5 Entity Framework Server Side
Hi im stuck in this problem for almost a week now i need help to create a server side pagination , sorting , filtering
ive done so many ways i found in internet but non work i already filter the data and its showing the problem is the pagination sorting and filtering
my table initialization
function testing3() {
$("#ModalSearchTable").dataTable().fnDestroy();
var searchVal = $("#ModalSearchValue").val();
var table = $("#ModalSearchTable").dataTable({
"searching": false,
"dom": 'frtip',
responsive: true,
"oLanguage":
{
"oPaginate":
{
"sFirst": "<<",
"sLast": ">>",
"sNext": ">",
"sPrevious": "<"
},
"sLengthMenu": "",
"sZeroRecords": "No Records Found"
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '@Url.Action("GetSearchData", "BusinessCenters")',
"fnServerData": function (sSource, aoData, fnCallback) {
/* Add some data to send to the source, and send as 'POST' */
aoData.push({ "name": "searchParam", "value": searchVal })
$.ajax({
"dataType": "JSON",
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
"columns": [
{ "data": "Id" ,
"class": "hidden",
"sTitle": "Id",
},
{
"data": "Code",
"sTitle": "Code",
},
{
"data": "Name",
"sTitle": "Name",
}
]
});
}
my jason request
public JsonResult GetSearchData(string searchParam)
{
var bussCtrs = db.BusinessCenters
.Where(x => searchParam == "*" || x.BussCtrCode.Contains(searchParam) || x.BussCtrName.Contains(searchParam))
.ToList()
.Select(x => new { Id = x.BussCtrId, Code = x.BussCtrCode, Name = x.BussCtrName });
return Json(new { aaData = bussCtrs }, JsonRequestBehavior.AllowGet);
}
Answers
It doesn't look like you've implemented server-side processing. Do you need server-side processing (50k+ rows)?
Allan
yes sir i need to add the server side processing but i dont know how it can be added using my current codes
Me neither . I haven't used EF very much. All I can really suggest is that you read over the server-side processing documentation I linked to above and write your EF code to match those client / server requirements.
Allan
its really hard for me because i almost try every approach i find in internet
I'd suggest that you need to ask in a C# forum in that case as that is outside of the scope of support that I can provide. I'm happy to answer any questions you might have about the client / server communication that DataTables expects, but EF is something I know very little about.
Allan
i finally did it hehe thanks this thread is closed now hehe
Hi you can find here. Sorry for the delay.
http://reddyinfosoft.blogspot.in/2016/12/jquery-datatable-in-mvc.html
http://reddyinfosoft.blogspot.in/2016/12/jquery-datatable-multisearch-paging-in.html
http://reddyinfosoft.blogspot.in/2016/12/jquery-datatable-paging-sorting-and.html
Hi, you can try this library:
https://github.com/VladimirDimov/jQuery-Datatables-Server-Side-Processing