I’m working with legacy code and the code uses editurl : ‘/folder/MethodName’ to send data to the backend when the delete button is clicked. The MethodName method signature is as below.
public ActionResult MethodName(string operation, Customer Model, string name)
The legacy code is giving me such a hard time as I can’t find any good article online that shows how to pass data to my MVC controller method (seen above) using editurl.
When I click on the trash can icon to delete the grid rows I’ve selected using multiselect, I want to use AJAX which is defined in the onSubmitClick property in the Delete section of jqGrid, to directly call the method MethodName and send data to it.
When I try to do that I get a modal asking me to confirm whether or not to delete the selected rows and my AJAX code in the onSubmitClick never gets called.
Instead of handling the delete using code in the Delete section of jqGrid when the trash can icon is clicked, the legacy code uses code for Edit and decides what to do based on the operation user selected and this confuses me.
Normally to post data to the backend I would use postData but in the legacy code I’m working with, I do not see postData.
So could you please do me a big favor and show me how to mark each of the data in jqgrid that I want to send to server side methods as parameters when editurl is used.
Hi, Thank you for your response. I’ve already figured out the problem and I ended up using server-side code to do the filtering.
How Do I edit my post as I have posted incorrect code and I would like to modify it so that you don’t get confused
Hi after taking the limitations of setting loadonce to true into consideration (which is needed for client-side filtering to work), I decided to do server-side filtering. Below is my server side code for filtering.
public JsonResult DisplayCustDetails(string sidx, string sord, int page, int rows, bool _search, string filters)
{
var serializer = new JavaScriptSerializer();
//var context = new HaackOverflowEntities();
var CustExcelData = TempData[“ExcelData”] as List < CustDataResponse > ;
TempData.Keep(“ExcelData”);
JqGridFilters f = (!_search || string.IsNullOrEmpty(filters)) ? null : serializer.Deserialize < JqGridFilters > (filters);
if (CustExcelData != null) {
var CustDetails = CustExcelData.Where(a => a.InUse == true);
sord = (sord == null) ? “” : sord;
int pageIndex = Convert.ToInt32(page) – 1;
int pageSize = rows;
var totalRecords = CustDetails.Count();
var totalPages = (int) Math.Ceiling((float) totalRecords / (float) rows);
if (f != null && f.rules != null && f.rules.Count > 0) {
foreach(JqGridFilters.Rule rule in f.rules) {
switch (rule.field) {
.
.
.
break;
case “Invoice_Date”:
if (rule.op.ToString() == “cn”) {
CustDetails = CustDetails.Where(t => t.Invoice_Date.ToString().ToLower().Contains(rule.data.ToLower()));
} else if (rule.op.ToString() == “eq”) {
CustDetails = CustDetails.Where(t => t.Invoice_Date.ToString().ToLower().Equals(rule.data.ToLower()));
} else if (rule.op.ToString() == “lt”) {
CustDetails = CustDetails.Where(t => t.Invoice_Date < Convert.ToDateTime(rule.data));
} else if (rule.op.ToString() == “le”) {
CustDetails = CustDetails.Where(t => t.Invoice_Date <= Convert.ToDateTime(rule.data));
} else if (rule.op.ToString() == “gt”) {
CustDetails = CustDetails.Where(t => t.Invoice_Date > Convert.ToDateTime(rule.data));
} else if (rule.op.ToString() == “ge”) {
CustDetails = CustDetails.Where(t => t.Invoice_Date >= Convert.ToDateTime(rule.data));
}
break;
.
.
.
}
}
}
switch (sidx) {
.
.
.
break;
case “Invoice_Date”:
if (sord.ToUpper() == “DESC”) {
CustDetails = CustDetails.OrderByDescending(t => t.Invoice_Date);
CustDetails = CustDetails.Skip(pageIndex * pageSize).Take(pageSize);
} else {
CustDetails = CustDetails.OrderBy(t => t.Invoice_Date);
CustDetails = CustDetails.Skip(pageIndex * pageSize).Take(pageSize);
}
break;
.
.
.
}
var jsnData = new {
total = totalPages,
page,
records = totalRecords,
rows = CustDetails
};
return Json(jsnData, JsonRequestBehavior.AllowGet);
}
} catch (Exception ex) {
}
return null;
}
Also you mentioned that you need to know my setup. What do you mean by setup?
I’m trying to filter on client side. I’ve looked at many posts and tutorial but I still can’t get it to work.
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top