1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| public ActionResult AjaxHandler(jQueryDataTableParamModel param)
{
//***************** Filtrage des pv avec le champs de recherche *******************
IEnumerable<V_EcranSupp_Tous_Web> filteredResult;
if (!string.IsNullOrEmpty(param.sSearch))
{
filteredResult = _db.SM_EcranSupp_Tous_Web("En Application", "En Projet", "Obsolète")
.Where(c => c.REFERENCE_PV.Contains(param.sSearch)
||
c.INDICE.Contains(param.sSearch)
||
c.TYPE.Contains(param.sSearch)
||
c.SOUS_TYPE.Contains(param.sSearch)
||
c.N_CONSTR.Contains(param.sSearch)
||
c.PUBLICATION.Contains(param.sSearch)
||
c.DATE_DE_PUB.Contains(param.sSearch)
||
c.IDPVREF.Contains(param.sSearch)
||
c.TYPEPVLIB.Contains(param.sSearch)).ToList();
}
else
{
filteredResult = _db.SM_EcranSupp_Tous_Web("En Application","En Projet","Obsolète").ToList();
}
//******************** Triage des colonnes ***************************
var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
Func<V_EcranSupp_Tous_Web, string> orderingFunction = (c =>
sortColumnIndex == 0 ? c.REFERENCE_PV :
sortColumnIndex == 1 ? c.INDICE :
sortColumnIndex == 2 ? c.TYPE :
sortColumnIndex == 3 ? c.SOUS_TYPE :
sortColumnIndex == 4 ? c.N_CONSTR :
sortColumnIndex == 5 ? c.PUBLICATION :
sortColumnIndex == 6 ? c.DATE_DE_PUB :
sortColumnIndex == 7 ? c.IDPVREF : c.TYPEPVLIB);
var sortDirection = Request["sSortDir_0"]; // asc or desc
if (sortDirection == "asc")
filteredResult = filteredResult.OrderBy(orderingFunction);
else
filteredResult = filteredResult.OrderByDescending(orderingFunction);
//******************** Retour des données **************************
var displayedResult = filteredResult
.Skip(param.iDisplayStart)
.Take(param.iDisplayLength);
var result = from c in displayedResult
select new[] { c.REFERENCE_PV, c.INDICE, c.TYPE, c.SOUS_TYPE, c.N_CONSTR, c.PUBLICATION, c.DATE_DE_PUB, c.IDPVREF, c.TYPEPVLIB };
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = _db.V_EcranSupp_Tous_Web.Count(),
iTotalDisplayRecords = filteredResult.Count(),
aaData = result
},
JsonRequestBehavior.AllowGet);
} |
Partager