Why isn't my jqGrid passing additional form data? - post

I'm using ASP.Net MVC 4 with a jqGrid, and I'm trying to pass an additional value from the form into the Add and Edit controller methods when jqGrid add/edits a record. My jqGrid looks like this:
$('#jqgRulesSetupVariablesList').jqGrid({
data: JSON.stringify(("#GroupDDL").valueOf()),
contentType: 'application/json; charset=utf-8',
//url from wich data should be requested
url: '#Url.Action("GetRulesSetupVariables")',
ondblClickRow: function (rowid) {
jQuery(this).jqGrid('editGridRow', rowid,
{ url: '#Url.Action("UpdateRulesSetupVariable")', recreateForm: true, closeAfterEdit: true, closeOnEscape: true, reloadAfterSubmit: false });
},
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: ['ID', 'Name', 'Description', 'Type'],
//columns model
colModel: [
{ name: 'ID', index: 'ID', align: 'left', width: '30px', editable: false, key: true },
{ name: 'Name', index: 'Name', align: 'left', width: '100px', editable: true, edittype: 'text', editoptions: { maxlength: 20 }, editrules: { required: true } },
{ name: 'Description', index: 'Description', align: 'left', width: '260px', editable: true, edittype: 'text', editoptions: { maxlength: 80 }, editrules: { required: true } },
{ name: 'Type', index: 'Type', align: 'left', width: '25px', editable: true, edittype: 'text', editoptions: { maxlength: 1 }, editrules: { required: true } },
],
//pager for grid
pager: $('#jqgRulesSetupVariablesPaging'),
//number of rows per page
rowNum: 10,
//initial sorting column
sortname: 'Name',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
//grid height
height: 230,
width: 450,
});
$('#jqgRulesSetupVariablesList').jqGrid('navGrid', '#jqgRulesSetupVariablesPaging',
{ add: true, del: false, edit: true, search: false },
// Edit Options
{ url: '#Url.Action("UpdateRulesSetupVariable")', closeAfterEdit: true, closeOnEscape: true, editData: { GroupName: function () { return "ABC"; } } },
// Add Options
{ url: '#Url.Action("InsertRulesSetupVariable")', closeAfterAdd: true, closeOnEscape: true, editData: { GroupName: function () { return "ABC"; } } },
// Delete options
{}
);
My controller is:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateRulesSetupVariable(RulesSetupVariableViewModel viewModel, string GroupName)
{
bool updateSuccess = UpdateRulesSetupVariable_Internal(viewModel);
return Json(updateSuccess);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InsertRulesSetupVariable(RulesSetupVariableViewModel viewModel, string GroupName)
{
bool updateSuccess = UpdateRulesSetupVariable_Internal(viewModel);
return Json(updateSuccess);
}
and my model:
public class RulesSetupVariableViewModel
{
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Type { get; set; }
}
The ID, Name, Description and Type are all coming through just fine, but the GroupName is not.
Any ideas what I'm doing wrong here?

I figured it out. Dumb mistake. I was using the doubleClick to edit the row. I modified this line
jQuery(this).jqGrid('editGridRow', rowid,
{ url: '#Url.Action("UpdateRulesSetupVariable")',
recreateForm: true,
closeAfterEdit: true,
closeOnEscape: true,
reloadAfterSubmit: false });
},
to this:
jQuery(this).jqGrid('editGridRow', rowid,
{ url: '#Url.Action("UpdateRulesSetupVariable")',
recreateForm: true,
closeAfterEdit: true,
closeOnEscape: true,
reloadAfterSubmit: false,
editData: { GroupName: function () { return $("#GroupDDL").val(); } }
},
This fixed my problem.

Related

How to use data from Model to bind as kendo datasource

i have an empty div that i want to initialize into a kendo grid using data from Model..it should be something like the following but i am unable to load data
$("#mapsDiv").kendoGrid({
sortable: true,
dataSource: {
transport: {
read:"/Home/About",
dataType: "odata"
},
pageSize: 5
},
pageable: true,
resizable: true,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell"
});
About.cshtml
#model List<KendoExample.Entities.ShortStudent>
<div class="row">
<div class="col-md-12 table-responsive" id="mapsDiv">
</div>
My Home Controller is as follows
List<ShortStudent> students = new List<ShortStudent>();
ShortStudent student1 = new ShortStudent();
student1.birthdate = new DateTime(1999, 4, 30);
student1.classname = "1B";
student1.firstname = "Fredie";
student1.surname = "Fletcher";
student1.studentid = 1;
ShortStudent student2 = new ShortStudent();
student2.birthdate = new DateTime(2010, 5, 4);
student2.classname = "1B";
student2.firstname = "Lee";
student2.surname = "Hobbs";
student2.studentid = 2;
students.Add(student1);
students.Add(student2);
return View(students);
I have seen examples using json but not odata...
Also, there are examples to use it like
#(Html.Kendo().Scheduler<MeetingViewModel>()
.Name("scheduler")
.Editable(false)
.DataSource(ds => ds
.Custom()
.Batch(true)
.Schema(schema => schema
.Model(m =>
{
m.Id(f => f.MeetingID);
m.Field("title", typeof(string)).DefaultValue("No title").From("Title");
m.Field("start", typeof(DateTime)).From("Start");
m.Field("end", typeof(DateTime)).From("End");
m.Field("description", typeof(string)).From("Description");
m.Field("recurrenceID", typeof(int)).From("RecurrenceID");
m.Field("recurrenceRule", typeof(string)).From("RecurrenceRule");
m.Field("recurrenceException", typeof(string)).From("RecurrenceException");
m.Field("isAllDay", typeof(bool)).From("IsAllDay");
m.Field("startTimezone", typeof(string)).From("StartTimezone");
m.Field("endTimezone", typeof(string)).From("EndTimezone");
}))
.Transport(new {
//the ClientHandlerDescriptor is a special type that allows code rendering as-is (not as a string)
read = new Kendo.Mvc.ClientHandlerDescriptor() {HandlerName = "customRead" }
})
)
)
which i am unable to understand/implement so please ignore this kind of a solution.
Currently i see a grid footer that says (1 - 2 of 4852 items) without any header or content(datarows) on my screen. What am I doing wrong?
UPDATE
var dataSource = new kendo.data.DataSource(
{
transport: {
read: {
url: '#Url.Action("About", "Home")',
contentType: "application/json",
dataType: "json"
}
},
schema: {
model: {
fields: {
firstname: { type: "string" },
surname: { type: "string" },
birthdate: { type: "date" },
classname: { type: "string" }
}
}
},
type: "json",
serverPaging: false,
serverFiltering: true,
serverSorting: false
}
);
$("#mapsDiv")
.kendoGrid(
{
sortable: true,
dataSource: {
transport: {
read: dataSource
},
pageSize: 2
},
pageable: true,
resizable: false,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell",
columns:[{
field: "firstname",
},{
field: "surname",
},{
field: "classname",
},{
field: "age",
}]
});
HomeController
public ActionResult About()
{
....
return View(students);
}
Now the grid with header is there but no data is present..
If i change action to json, it returns plain json on the page
public ActionResult About()
{
....
return Json(students, JsonRequestBehavior.AllowGet);
}
Have you tried adding the fields to the grid?
$("#mapsDiv")
.kendoGrid(
{
sortable: true,
dataSource: {
transport: {
read:"/Home/About",
dataType: "odata"
},
pageSize: 5
},
columns: [
{
field: "classname",
title: "Class Name"
},
{
field: "firstname",
title: "First name"
},
{
field: "surname",
title: "Last name"
}
],
pageable: true,
resizable: true,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell"
});
I just visit demo of telerik. Try following. Hope to help, my friend. Or you can visit this link to refer more: http://demos.telerik.com/kendo-ui/grid/remote-data-binding.
$("#mapsDiv")
.kendoGrid(
{
sortable: true,
dataSource: {
transport: {
read:"/Home/About",
dataType: "odata"
},
pageSize: 5
},
schema: {
model: {
fields: {
studentid: { type: "number" },
birthdate : { type: "date" },
classname : { type: "string" },
firstname : { type: "date" },
surname : { type: "string" }
}
}
},
pageable: true,
resizable: true,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell"
});
So here is what i found what should have been straight forward :)
var values = #Html.Raw(Json.Encode(#Model));
$("#MapDetails")
.kendoGrid(
{
sortable: true,
dataSource: {
data:values,
pageSize: 2
},
pageable: true,
resizable: false,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell",
columns:[{
field: "firstname",
},{
field: "surname",
},{
field: "classname",
},{
field
: "age",
}]
});

JQGrid is not loading data in MVC 5?

I am using jqgrid and table is working correctly. But no data is loading and it continuesly displaying "loading...". It worked correctly but i maybe due to some reason it is not working now.
public JsonResult GetDetails()
{
Database1Entities db = new Database1Entities();
var jsondata = new
{
total = 1,
page = 1,
records = db.Employees.ToList().Count.ToString(),
rows = db.Employees.Select(a => new {
a.Id,a.Name,a.Designation,a.Address,a.Salary
})
};
return Json(jsondata, JsonRequestBehavior.AllowGet);
}
JQGrid function is below:
$(document).ready(function () {
$("#Grid").jqGrid({
url: '/Home/GetDetails',
datatype: 'json',
myType: 'GET',
colNames: ['id','Name', 'Designation', 'Address', 'Salary'],
colModel: [
{ key: false, name: 'Id', index: 'Id', },
{ key: false, name: 'Name', index: 'Name', editable: true },
{ key: false, name: 'Designation', index: 'Designation', editable: true },
{ key: false, name: 'Address', index: 'Address', editable: true },
{ key: false, name: 'Salary', index: 'Salary', editable: true }
],
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
records: 'records',
id: '0',
repeatitems: false
},
pager: $('#pager'),
rowNum: 10,
rowList: [10, 20, 30],
width: 600,
viewrecords: true,
multiselect: true,
sortname: 'Id',
sortorder: "desc",
caption: 'Employee Records',
loadonce: true,
}).navGrid('#pager', { edit: true, add: true, del: true },
{
zIndex: 100,
url: '/Home/Edit',
closeOnEscape: true,
closeAfterEdit: true,
recreateForm: true,
afterComplete: function (response) {
if (response.responseText)
{
alert(response.responseText);
}
}
},
{
zIndex: 10,
url: '/Home/Add',
closeOnEscape: true,
closeAfterEdit: true,
recreateForm: true,
afterComplete: function (response) {
if (response.responseText) {
alert(response.responseText);
}
}
},
{
zIndex: 100,
url: '/Home/Delete',
closeOnEscape: true,
closeAfterEdit: true,
recreateForm: true,
afterComplete: function (response) {
if (response.responseText) {
alert(response.responseText);
}
}
}
);
});
If i add something, it works and data is inserted into database but the main problem is not data is shown in JQGrid. What is the problem?

jqgrid not showing any results when count exceeds ~9000

I am using jqgrid version 4.1.2 with MVC4, using loadonce option. When the search result's count exceeds approximately 9000 records, no data is shown up on the grid.
What might be the issue?
Here is the JS code: Update 1
function showCompletedGrid() {
// Set up the jquery grid
$("#jqTableCompleted").jqGrid({
// Ajax related configurations
url: jqDataUrl,
datatype: "json",
mtype: "POST",
loadonce: true,
loadtext: 'Loading Data please wait ...',
postData: { strUserName: function () { return $('#ddlUserName :selected').val(); },
strFunctionName: function () { return $('#ddlOPMSFunction :selected').text(); },
strProcName: function () { return $('#ddlOPMSProcess :selected').text(); },
strCategory: function () { return $('#ddlSearchCategory :selected').text(); },
strWorkType: function () { return $('#ddlSearchWorkType :selected').text(); },
strRequestNumber: function () { return $('#txtRequestNo').val(); },
strStatus: function () { return $('#ddlSearchStatus :selected').text(); },
strFromDate: function () { return $('#txtFromDate').val().toString(); }, //datepicker('getDate'),
strToDate: function () { return $('#txtToDate').val().toString(); }, //datepicker('getDate'),
strAction: "Closed"
},
autowidth: true,
shrinkToFit: true,
// Specify the column names
colNames: ["S.No.", "User Name", "Category", "Work Type", "Request Number", "Status", "Time Spent", "RE", "GUID", "Marked for Correction", "Correction Complete", "Reason", "Task Type", "acf2id", "Created Date", "Action", "IsTeam"],
// Configure the columns
colModel: [
{ name: "SNo", index: "SNo", sorttype: 'int', width: 100, align: "left", hidden: true, sortable: true, search: true, searchoptions: { sopt: ['eq']} },
{ name: "UserName", index: "UserName", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "Category", index: "Category", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "WorkType", index: "WorkType", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "RequestNumber", index: "RequestNumber", width: 200, align: "left", sortable: true, search: true, searchoptions: { sopt: ['cn']} },
{ name: "Status", index: "Status", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "TimeSpent", index: "TimeSpent", width: 200, align: "left", sortable: true, search: true },
{ name: "RE", index: "RE", width: 200, align: "left", sortable: true, search: true },
{ name: "GUID", index: "GUID", sortable: false, search: false, width: 200, align: "left", hidden: true },
{ name: "MarkCorrection", index: "MarkCorrection", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "CorrectionComplete", index: "CorrectionComplete", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "Reason", index: "Reason", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "TaskType", index: "TaskType", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "acf2id", index: "acf2id", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
{ name: "CreatedDate", index: "CreatedDate", width: 200, align: "left", hidden: false, search: false },
{ name: 'Actions', sortable: false, search: false, fixed: true, align: 'center', formatter: returnHyperLinkCompleted },
{ name: 'IsTeam', sortable: false, hidden: true, search: false, fixed: true, align: 'center' }
],
ignoreCase: true,
//width: 1250,
height: 150,
// Paging
toppager: true,
pager: $("#jqTableCompletedPager"),
//rowTotal: 200,
rowNum: 20,
rowList: [20, 15, 10, 5],
viewrecords: true,
emptyrecords: "",
hiddengrid: true,
// Default sorting
sortname: "SNo",
sortorder: "asc",
// Grid caption
caption: "Closed",
loadComplete: function (data) {
var RE;
var TimeSpent;
var rowIDs = jQuery("#jqTableCompleted").jqGrid('getDataIDs');
for (var i = 0; i < rowIDs.length; i++) {
var rowID = rowIDs[i];
var row = jQuery('#jqTableCompleted').jqGrid('getRowData', rowID);
RE = hmsToSecondsOnly(row.RE);
RE = (0.2 * RE) + RE;
TimeSpent = hmsToSecondsOnly(row.TimeSpent);
if (TimeSpent > RE && RE > 0) {
$(row).removeClass('ui-widget-content');
$(row).removeClass('ui-state-highlight');
$("#jqTableCompleted tr[id='" + rowID + "']").addClass('myColor');
}
}
}
}).navGrid("#jqTableCompletedPager",
{ refresh: true, add: false, edit: false, del: false },
{}, // settings for edit
{}, // settings for add
{}, // settings for delete
{sopt: ["cn"]}
);
$("#jqTableCompleted").jqGrid('navGrid', '#jqTableCompletedPager', { del: false, add: false, edit: false, search: false });
$("#jqTableCompleted").jqGrid('filterToolbar', { searchOnEnter: false, searchOperators: true });
$("#jqTableCompleted").jqGrid('navButtonAdd', '#jqTableCompletedPager',
{ caption: "Export to Excel", buttonicon: "ui-icon-extlink", title: "Export", id: "btnExport",
onClickButton: function (evt) {
var UserName = $('#ddlUserName option:selected').val();
var RequestNumber = $('#txtRequestNo').val();
var FunctionName = encodeURIComponent($('#ddlOPMSFunction option:selected').text());
var ProcessName = encodeURIComponent($('#ddlOPMSProcess option:selected').text());
var Category = $('#ddlSearchCategory option:selected').text();
var WorkTypeName = $('#ddlSearchWorkType option:selected').text();
var SearchStatus = $('#ddlSearchStatus option:selected').text();
var TransactionStartTS = $('#txtFromDate').val().toString();
var TransactionEndTS = $('#txtToDate').val().toString();
window.open("../Search/Export?UserName=" + UserName + "&RequestNumber=" + RequestNumber + "&FunctionName=" + FunctionName + "&ProcessName=" + ProcessName + "&Category=" + Category + "&WorkTypeName=" + WorkTypeName + "&SearchStatus=" + SearchStatus + "&TransactionStartTS=" + TransactionStartTS + "&TransactionEndTS=" + TransactionEndTS + "&ActionName=" + "Closed");
}
});
}
Although the data is being returned and in the correct format, from the controller, as follows, the grid does not show any result.
var jsonData = new
{
page = page,
rows = data
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
Also is there any limit on number of records or dependency on the browser when returning all the data from server using the loadonce option?
Any help would be much appreciated. Thanks.
Finally I found the solution for the above problem by tracing the request in Fiddler, in the response title following error was shown:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Upon searching for the above error, I found a workaround:
Here
Basically the problem area was not the jqGrid, but was MaxJsonLength property of JavaScriptSerializer which defaults to 2097152 characters ~ 4 MB of data. Source: MaxJsonLength
To get it working, I replaced the following code in my Action method:
return Json(jsonData, JsonRequestBehavior.AllowGet);
with:
var jsonResult = Json(jsonData, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
Thanks.

issue with filterToolbar in jqGrid Search

search functionality is not working. when hitting action method in controller parameters looking like "_search=true", "searchField=null", "searchString=null" ,"searchOper=null", here i am not getting values of searchField,searchString,searchOper. Please can any one help.
if i give loadonce: true property then search is working. but i am getting first page records only. i am not getting other page records. How can i fix this.
My code:
$(function () {
$("#Channelslistgrid").jqGrid({
colNames: ['ChannelName', 'Description', 'status'],
colModel: [
{ name: 'ChannelName', index: 'ChannelName', sortable: true, align: 'left', width: '200',
editable: false, edittype: 'text',search:true
},
{ name: 'Description', index: 'Description', sortable: false, align: 'left', width: '120',
editable: false, edittype: 'text',search:true
},
{ name: 'status', index: 'status', sortable: false, align: 'left', width: '220',
editable: false, edittype: 'text',search:true
},
],
pager: jQuery('#pager'),
sortname: 'Title',
rowNum: 15,
rowList: [15, 20, 25],
sortorder: "desc",
height: 345,
ignoreCase: true,
viewrecords: true,
rownumbers: true,
caption: 'Channels List',
width: 660,
url: "#Url.Content("~/Home/Channelslist")",
datatype: 'json',
mtype: 'GET',
loadonce: true
})
jQuery("#Channelslistgrid").jqGrid('filterToolbar', { searchOnEnter: true, enableClear: false });
});
controller
public ActionResult Channelslist(int page, int rows, string sidx, string sord, bool _search, string searchField, string searchString, string searchOper)
{
//code
}
Instead you can use the below controller code to get the search parameters typed on the filtertoolbar.
public ActionResult Channelslist(int page, int rows, string sidx, string sord, bool _search) {
string ChannelName= "";
string desc= "";
if (Request.Params["ChannelName"] != null) ChannelName = Request.Params["ChannelName"];
if (Request.Params["Description "] != null) desc= Request.Params["Description"];
}

posting additional data in edit mode of jquery jqgrid and custom validations for inline editing

Im using jqgrid wherein i need to pass addtional data to the controller while editing... but i m not able to do so... here is my code below..
<script type="text/javascript">
//
var checkMileageLimit = function (value, colname) {
var clName = (colname == 'MileageLimitPM' ? 'MileageLimitAM' : 'MileageLimitPM');
if (parseInt(value) + parseInt($('#' + clName).val()) > parseInt($("#TotalMileage").val())) {
return [false, "sum of AM and PM mileage should not exceed Total Mileage", ""];
}
else return [true, "", ""];
};
var checkTouchLimit = function (value, colname) {
var clName = (colname == 'TouchLimitPM' ? 'TouchLimitAM' : 'TouchLimitPM');
if (parseInt(value) + parseInt($('#' + clName).val()) > parseInt($("#TotalTouches").val())) {
return [false, "sum of AM and PM Touches should not exceed Total Touches", ""];
}
else return [true, "", ""];
};
var lastsel;
$("#list").jqGrid({
url: '<%= Url.Action("GetScheduleInfo", "TouchSchedule") %>',
datatype: 'json',
mtype: 'GET',
postData: {
StartDate: function () { return $('#StartDate').val(); },
EndDate: function () { return $('#EndDate').val(); },
siteId: function () { return $('#ListFacility').length == 0 ? -1 : $('#ListFacility').val(); }
},
colNames: ['RowID', 'SiteID', 'CalDate', 'Store Open', 'Start Time', 'End Time',
'MileageLimit AM', 'MileageLimit PM', 'TouchLimit PM',
'TouchLimit AM', 'Total Touches', 'Total Mileage', 'WeekDay'],
colModel: [
{ name: 'RowID', index: 'RowID', width: 40, key: true, editable: true, editrules: { edithidden: false }, hidedlg: true, hidden: true },
{ name: 'SiteID', index: 'SiteID', width: 40, /* key: true,*/editable: true, editrules: { edithidden: false }, hidedlg: true, hidden: true },
{ name: 'CalDate', index: 'CalDate', width: 100, formatter: 'date', datefmt: 'm/d/Y', editable: false, formoptions: { elmsuffix: ' *'} },
{ name: 'StoreOpen', index: 'StoreOpen', width: 40, editable: true, edittype: 'select', formatter: 'select', editrules: { required: true }, formoptions: { elmsuffix: ' *' }, editoptions: { value: { o: 'Open', c: 'closed'} }, width: "40" },
{ name: 'StartTime', index: 'StartTime', width: 100, editable: true, formatter: 'date', masks: 'ShortTime', edittype: 'text', editrules: { time: true, required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'EndTime', index: 'EndTime', width: 100, editable: true, edittype: 'text', editrules: { time: true, required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'MileageLimitAM', index: 'MileageLimitAM', width: 50, editable: true, formatter: 'integer',
edittype: 'text', editrules: { custom: true, custom_func: checkMileageLimit,
required: true
}, formoptions: { elmsuffix: ' *' }
},
{ name: 'MileageLimitPM', index: 'MileageLimitPM', width: 50, editable: true, edittype: 'text', formatter: 'integer', editrules: { custom: true, custom_func: checkMileageLimit, required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'TouchLimitAM', index: 'TouchLimitAM', width: 50, editable: true, edittype: 'text', formatter: 'integer', editrules: { custom: true, custom_func: checkTouchLimit, required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'TouchLimitPM', index: 'TouchLimitPM', width: 50, editable: true, edittype: 'text', formatter: 'integer', editrules: { custom: true, custom_func: checkTouchLimit, required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'TotalTouches', index: 'TotalTouches', width: 50, editable: true, edittype: 'text', editrules: { required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'TotalMileage', index: 'TotalMileage', width: 50, editable: true, edittype: 'text', editrules: { required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'WeekDay', index: 'WeekDay', width: 200, editable: false, hidden: false }
],
pager: $('#listPager'),
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'CalDate',
sortorder: "desc",
viewrecords: true,
caption: 'Schedule Calendar',
autowidth: false,
gridview: true,
id: "RowID",
ondblClickRow: function (id) {
if (id && id !== lastsel) {
jQuery('#list').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('editGridRow', id,{ onclickSubmit});
lastsel = id;
}
}
, editurl: '<%= Url.Action("UpdateGrid", "TouchSchedule") %>'
}).navGrid('#listPager',
{ edit: true, add: false, del: false, search: false, refresh: true },
{width:400,height:400,closeAfterEdit:true,
onclickSubmit:function(params) { var ajaxData = {};
var list = $("#list");
var selectedRow = list.getGridParam("selrow");
rowData = list.getRowData(selectedRow);
ajaxData = { CalDate: rowData.CalDate };
return ajaxData; }}
);
$('#btnSubmit').click(function () {
$("#list").clearGridData();
$("#list").trigger("reloadGrid");
});
});
//]]>
Please let me know where i m going wrong... also i have observed that if i use inline editing then the custom validation is not being fired? how to solve this problem via inline editing?
thanks in advance...
First of all you don't use inline editing at all in your code. You use editGridRow and in a wrong way:
jQuery('#list').jqGrid('editGridRow', id,{ onclickSubmit});
instead of the usage of editRow used in the inline editing mode.
You should at least set a value for the onclickSubmit event handle:
jQuery('#list').jqGrid('editGridRow', id,
{ onclickSubmit : function(params, posdata) {
alert ("in onclickSubmit");
// ...
}
});
Moreover you try to use validation based not on the value parameter which you receive as a parameter of the custom validation function. You try to read another text fields. You should understand, that it is not the best way. Moreover in case of inline editing the text fields will nave the ids not like the corresponding names of the columns. So the usage of $("#TotalMileage") will be OK for the form editing, but it should be $("#"+rowid+"_TotalMileage") in case of inline editing.
You can consider to use beforeCheckValues function additionally which will get use all fields of the data which will be posted. The function will be called before verifying of every field of the form. In case of inline editing this is not possible, so you will have to detect in any way the mode which you use (for example you can set a variable which define the current manually) and use the corresponding name conversion of the field ids. Another way is the usage of dataEvents with for example 'change' event handler.
To send additional data in case of form editing you can use editData, return the object with the additional data from onclickSubmit or you custom serializeEditData function. You can also modify the url used during data posting inside of the onclickSubmit function.
To send additional data in inline editing mode you can use extraparam parameter of the editRow or use inlineData parameter of the jqGrid.
One more remark at the end. You should start to use voting up of your answers and accepting the answers. At least you have comment another answer and post additional information needed to answer on your questions. For example some time ago you asked already almost the same question and I asked you to post HTML code. Many other your questions stay uncommented and it is not clear whether you at least read there. It so will be continued you will be receive less or no answers at all.
At a glance I would say it has something to do with that you are using a GET and not a POST. Get will concatenate the data onto the query string. This might be interfering with the grid.

Resources