jqgrid reload is not working - asp.net-mvc-3

my code....
public string ConstructButtonEvents(string buttonid, string gridID, string GridControlId, string ActionUrl)
{
StringBuilder sbButtonEvents = new StringBuilder();
GridControlId = GridControlId.Trim();
sbButtonEvents.Append(" $('#" + buttonid + "').die().live('click', function () { ");
sbButtonEvents.Append("var SelectedArtifactDetails = new Array();");
sbButtonEvents.Append(" var CurrentArtifactDetails = new Array();");
sbButtonEvents.Append("for (var i = 0; i < $('#" + gridID + " tbody tr').length; i++) {");
sbButtonEvents.Append(" var rowId = jQuery('#" + gridID + " tr:eq(' + i + ')').attr('id');");
sbButtonEvents.Append("var row = $('#" + gridID + "').jqGrid('getRowData', rowId);");
sbButtonEvents.Append(" if (($('#Status" + GridControlId + "'+rowId).attr('checked') == 'checked') && ($('#Status" + GridControlId + "'+rowId).attr('disabled') != 'disabled')) {");
sbButtonEvents.Append("CurrentArtifactDetails = {");
sbButtonEvents.Append(" Complete: 'Y',");
sbButtonEvents.Append("StakeHolderEmail: $('#Stakeholder" + GridControlId + "'+rowId).attr('value'),");
sbButtonEvents.Append("UploadFile: $('#uploadFile" + GridControlId + "'+rowId).attr('value'),");
sbButtonEvents.Append("PhaseArtifactId: $(row).attr('ID'),");
sbButtonEvents.Append("Status: $('#list" + GridControlId + "'+rowId+' option:selected').text()");
sbButtonEvents.Append("};");
sbButtonEvents.Append("SelectedArtifactDetails.push(CurrentArtifactDetails);");
sbButtonEvents.Append("}");
sbButtonEvents.Append("}");
sbButtonEvents.Append(" $.ajax({");
sbButtonEvents.Append(" url: '" + ActionUrl + "',");
sbButtonEvents.Append(" async: false,");
sbButtonEvents.Append(" loadonce:false, type: 'POST', dataType: 'json', data: JSON.stringify(SelectedArtifactDetails), contentType: 'application/json; charset=utf-8',");
sbButtonEvents.Append(" success: function () {");
//sbButtonEvents.Append(" $('#" + gridID + "').jqGrid('GridUnload');");
sbButtonEvents.Append(" $('#" + gridID + "').trigger('reloadGrid');");
sbButtonEvents.Append(" }, error: function () { alert('error'); }");
sbButtonEvents.Append("});");
sbButtonEvents.Append("});");
return sbButtonEvents.ToString();
}
i have mutliple tabs yet the grid id generation is perfect. I'm constructing the grid in the .cs itself. i need to update the data in the rows to the DB. so, i have an update button... on click of it i post (ajax) the data. The data is getting updated pretty much well. But the grid is not getting reloaded.
on click of update button i fetch the values and then the below ajax post is called
$.ajax({ url: '/SDLCMClassic/EditProject/BatchUpdate',
type: 'POST',
dataType: 'json',
data: JSON.stringify(SelectedArtifactDetails),
contentType: 'application/json; charset=utf-8',
success: function () {
$('#tblArtifact1').trigger('reloadGrid');
}, error: function () { alert('error'); }
});
});
I'm able to fetch the row values in the grid and i'm able to post it successfully. It is getting updated in DB as well. But immediate reload is not happening. if i refresh the whole page then only i'm able to see the updated data.
Here is the code to construct jqgrid in js
$(function () {
$('#tblArtifact1').jqGrid({
url: '/SDLCMClassic/EditProject/FillArtifactGrid?ppmno=188035&phaseName=Project Startup',
datatype: 'json',
mtype: 'GET',
colNames: ['Artifact', 'Complete', 'Status', 'Stakeholder', 'App Reference', 'Document', 'URL', 'ID'],
colModel: [
{ name: 'Name', index: 'Name', editable: false, edittype: '', align: 'left', key: false, hidden: false, formatter: 'showlink', formatoptions: { target: '_blank', baseLinkUrl: '' }, width: $(window).width() * .1, sortable: false },
{ name: 'Complete', index: 'Complete', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .06, sortable: false },
{ name: 'Status', index: 'Status', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .10, sortable: false },
{ name: 'StakeHolderEmail', index: 'StakeHolderEmail', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .15, sortable: false },
{ name: 'App Reference', index: 'App Reference', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .15, sortable: false },
{ name: 'Document', index: 'Document', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .18, sortable: false },
{ name: 'URL', index: 'URL', editable: false, edittype: '', align: 'center', key: false, hidden: false, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .15, sortable: false },
{ name: 'ID', index: 'ID', editable: false, edittype: '', align: 'center', key: false, hidden: true, formatter: '', formatoptions: { target: '', baseLinkUrl: '' }, width: $(window).width() * .01, sortable: false }
],
viewrecords: true,
sortname: 'Complete',
sortorder: 'asc',
width: 'auto',
height: 'auto',
subGrid: true,
subGridRowExpanded: function (subgrid_id, row_id) {
$('#' + subgrid_id).html(renderhtmlforSubgrid(this, subgrid_id, row_id));
},
gridComplete: function () {
var dataIds = $('#tblArtifact1').jqGrid('getDataIDs');
for (var i = 0; i < dataIds.length; i++) {
$('#tblArtifact1').editRow(dataIds[i], false);
}
},
loadComplete: function () {
ModifyGridDefaultStyles('tblArtifact1');
}
});
});

You don't posted the most important part of the code: the code which defines jqGrid. So I have to guess.
Typical problem with not reloading of grid per .trigger('reloadGrid'); is because you use loadonce: true option in the jqGrid. It changes datatype from the initial "json" or "xml" value to datatype: "local". So reloading do work, but reload the local data. If you need to reload the data from the server you have to reset datatype to initial value "json" or "xml" before trigger reloadGrid. See the answer and the answer for more details.

Related

JqGrid paging with lots of grids

I have a single page ASP.Net web forms application. And lots of grids. In my application, there is some links to hide or show grids. The problem is, when i start the application, the pagination of the displayed grid is working properly. (I tried this for each grid). But when I Click the link for hide a grid and show another grid, paging does not working. The grid initialization is;
$('#tblApplicationSettings').jqGrid({
url: cms.util.getAjaxPage(),
cellLayout: cms.theme.list.cellLayout,
hoverrows: false,
forceFit: true,
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "",
id: "0"
},
width: 900,
height: 400,
datatype: 'local',
colNames: ['SettingId',
'Description',
'Name',
'Value',
'ServerId',
'IsReadOnly',
''
],
colModel: [
{
name: 'SettingId',
index: 'SettingId',
hidden: true
},
{
name: 'Description',
index: 'Description',
search: false,
editable: true,
sortable: false,
width: 150,
inlineEditable: true
},
{
name: 'Name',
index: 'Name',
search: false,
editable: false,
sortable: false,
width: 150,
inlineEditable: false
},
{
name: 'Value',
index: 'Value',
search: false,
editable: true,
sortable: false,
width: 250,
inlineEditable: true,
},
{
name: 'ServerId',
index: 'ServerId',
search: false,
editable: true,
sortable: false,
width: 150,
formatter: 'select',
edittype: 'select',
editoptions: {
value: options,
},
inlineEditable: true
},
{
name: 'IsReadOnly',
index: 'IsReadOnly',
hidden: true
},
{
name: 'JsUsage',
index: 'JsUsage',
search: false,
editable: true,
sortable: false,
width: 150,
inlineEditable: true
},
],
onSelectRow: function (id) {
if (id && id !== lastSelection) {
jQuery('#grid').jqGrid('restoreRow', lastSelection);
lastSelection = id;
}
var columnModel = $('#grid').getGridParam('colModel');
var colNames = new Array();
$.each(columnModel, function (index, column) {
colNames.push(column.name);
if (isReadOnly || !column.inlineEditable) {
column.editable = false;
}
else {
column.editable = true;
}
if (column.edittype == "select") {
column.editoptions.dataEvents = [{
type: 'change',
fn: function (e) {
var newServerId = $(this).val();
that.isServerIdChanged = true;
if (newServerId == "null") {
}
}
}]
}
});
var row = $('#grid').getRowData(id);
var isReadOnly = row.IsReadOnly == "true" ? true : false;
if (isReadOnly) {
alert("row is not editable");
return null;
}
jQuery("#grid").jqGrid('editRow', id, {
keys: true,
extraparam: {
dataType: 'updateSetting',
colNames: JSON.stringify(colNames),
settingName: row.Name,
settingId: row.SettingId
},
successfunc: function (result) {
$("#grid").trigger('reloadGrid');
}
});
},
editurl: '/Ajax.ashx',
rowNum: 25,
direction: "ltr",
scroll: 1,
gridview: true,
pager: '#divPager',
viewrecords: true,
});
$('#grid').setGridParam({ datatype: "json", postData: { dataType: 'getSettings' } });
$('#grid').jqGrid('navGrid', '#divPager', { edit: false, add: false, del: false, search: false, refresh: false });
$('#grid').trigger('reloadGrid');
like this for all grids. I need tips or helps. Thanks.

JqGrid with row specific dropdown?

Here is my current column model:
colModel: [
{ name: 'LastName', index: 'LastName', width: 120, align: 'center' },
{ name: 'FirstName', index: 'FirstName', width: 120, align: 'center' },
{ name: 'MiddleName', index: 'MiddleName', width: 120, align: 'center' },
{ name: 'DOB', index: 'DOB', width: 100, align: 'center' },
{ name: 'id', index: 'id', align: 'center', hidden: true },
{ name: 'checked', index: 'checked', align: 'center', hidden: true },
{ name: 'courtType', index: 'courtType', align: 'center', editable: true, sortable: false, width: 100 },
{ name: 'CaseNumber', index: 'CaseNumber', align: 'center', editable: true, sortable: false, width: 100 },
{ name: 'CourtFileNumber', index: 'CourtFileNumber', align: 'center', editable: true, sortable: false, width: 100 },
{ name: 'WarrantDocket', index: 'WarrantDocket', align: 'center', editable: true, sortable: false, width: 100 },
{ name: 'Sentencing', index: 'Sentencing', align: 'center', editable: true, sortable: false, width: 100 },
{ name: 'notes', index: 'notes', align: 'center', editable: true, sortable: false, width: 400 },
{ name: 'name', index: 'name', width: 200,
sortable: true,
align: 'center',
editable: true,
cellEdit: true,
edittype: 'select',
formatter: 'select',
editoptions: { value: getAllSelectOptions() }
}
],
This gives me a dropdown list from getAllSelectOptions().
function getAllSelectOptions() {
var states = { '1': 'Alabama', '2': 'California', '3': 'Florida',
'4': 'Hawaii', '5': 'London', '6': 'Oxford'
};
return states;
}
Is there a way to get a different list for each row based on its ID and a webmethod call (or some other way)?
var createCourtGridURL = AdminPath + "WebMethods/Kernel/Court.asmx/GetGetdData";
var jqGridDataURL = AdminPath + "WebMethods/Kernel/Court.asmx/GetSelectData";
Edit: Working Code
var myGrid = $('#selectedInmateList'),
decodeErrorMessage = function (jqXHR, textStatus, errorThrown) {
var html, errorInfo, i, errorText = textStatus + '\n' + errorThrown;
if (jqXHR.responseText.charAt(0) === '[') {
try {
errorInfo = $.parseJSON(jqXHR.responseText);
errorText = "";
for (i = 0; i < errorInfo.length; i++) {
if (errorText.length !== 0) {
errorText += "<hr/>";
}
errorText += errorInfo[i].ExceptionType + ": " + errorInfo[i].Message;
}
}
catch (e) { }
} else {
html = /<body.*?>([\s\S]*)<\/body>/i.exec(jqXHR.responseText);
if (html !== null && html.length > 1) {
errorText = html[1];
} else {
errorText = jqXHR.responseText.replace(/\n/, "<br>");
}
}
return errorText;
},
buildSelectFromJson = function (data) {
var html = '<select>', d = data.d, length = d.length, i = 0, item;
for (; i < length; i++) {
item = d[i];
html += '<option value=' + item + '>' + item + '</option>';
}
html += '</select>';
return html;
};
myGrid.jqGrid({
url: createCourtGridURL,
datatype: 'json',
ajaxGridOptions: { contentType: "application/json" },
ajaxSelectOptions: { contentType: "application/json", dataType: 'json'/*, type: "POST"*/ },
serializeGridData: function (postData) {
if (postData.filters === undefined) postData.filters = null;
return JSON.stringify(postData);
},
mtype: 'POST',
colNames: ['Id', 'Last Name', 'First Name', 'Middle Name', 'DOB', 'Checked', 'User'],
colModel: [
{ name: 'id', index: 'id', align: 'center', hidden: true },
{ name: 'LastName', index: 'LastName', width: 120, align: 'center' },
{ name: 'FirstName', index: 'FirstName', width: 120, align: 'center' },
{ name: 'MiddleName', index: 'MiddleName', width: 120, align: 'center' },
{ name: 'DOB', index: 'DOB', width: 100, align: 'center' },
{ name: 'checked', index: 'checked', align: 'center', hidden: true },
{ name: 'User', index: 'User', width: 400, editable: true,
stype: 'select', edittype: 'select',
/*
searchoptions: {
sopt: ['cn', 'nc', 'bw', 'bn', 'eq', 'ne', 'ew', 'en', 'lt', 'le', 'gt', 'ge'],
dataUrl: jqGridDataURL,
buildSelect: buildSelectFromJson
},
*/
editoptions: {
sopt: ['cn', 'nc', 'bw', 'bn', 'eq', 'ne', 'ew', 'en', 'lt', 'le', 'gt', 'ge'],
dataUrl: function () {
var rowID = selectedRowId = myGrid.jqGrid('getGridParam', 'selrow');
return jqGridDataURL + '?id=' + rowID;
},
buildSelect: buildSelectFromJson,
dataEvents: [
{
type: 'change',
fn: function (e) {
//alert('change event')
}
}
]
}
}
],
pager: '#pager',
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: 'desc',
rownumbers: true,
viewrecords: true,
height: '100%',
cellEdit: true,
multiselect: true,
cellsubmit: 'clientArray', //?
pager: '#selectedInmatePager',
gridview: true,
jsonReader: {
root: "d.rows",
page: "d.page",
total: "d.total",
records: "d.records",
cell: ""
},
caption: 'Selected Court Inmates',
loadError: function (jqXHR, textStatus, errorThrown) {
// remove error div if exist
$('#' + this.id + '_err').remove();
// insert div with the error description before the grid
myGrid.closest('div.ui-jqgrid').before(
'<div id="' + this.id + '_err" style="max-width:' + this.style.width +
';"><div class="ui-state-error ui-corner-all" style="padding:0.7em;float:left;"><span class="ui-icon ui-icon-alert" style="float:left; margin-right: .3em;"></span><span style="clear:left">' +
decodeErrorMessage(jqXHR, textStatus, errorThrown) + '</span></div><div style="clear:left"/></div>');
},
loadComplete: function () {
// remove error div if exist
$('#' + this.id + '_err').remove();
}
});
myGrid.jqGrid('navGrid', '#selectedInmatePager', { add: false, edit: true, del: false },
{}, {}, {}, { multipleSearch: true, overlay: false, width: 480 });
You use dataUrl already. jqGrid supports dataUrl starting with 4.5.3. So you can define dataUrl as callback which get tree parameters rowid, value, columnName. So you can return from the dataUrl the URL which contains rowid as parameter. In the case the call to the dataUrl will be different for different rows any you can implement your requirements.

Howto pass extra param on SubGrid Jqgird

Suppose the following grids
$(document).ready(function() {
$('#Clientes').jqGrid({colNames: ['Razón Social','Cuit','Dirección','Localidad','Teléfono','Tipo IVA','Mail','Saldo inicial','Facturar'],
colModel: [{ editable: true, editoptions: { "maxlength":70 }, editrules: { required: true }, name: 'RazonSocial' },
{ editable: true, editoptions: { dataInit: CuitMask, "maxlength":13 }, editrules: { custom: true, custom_func: ValidateCuit, required: true }, name: 'NidentFiscal' },
{ editable: true, editoptions: { "maxlength":70 }, editrules: { required: true }, name: 'Direccion' },
{ editable: true, edittype: 'select', editoptions: { dataUrl: '/Ciudad/CmbCiudad' }, editrules: { required: true }, name: 'Ciudad' },
{ editable: true, editoptions: { "maxlength":20 }, name: 'Telefono' }],
url: '/Clientes/List',
datatype: 'json',
mtype: 'POST',
pager: '#ClientesPager',
prmNames: { id: 'ClienteId' },
rowList: [10,15,20,25,30],
sortname: 'ClienteId',
subGrid: true,
subGridRowExpanded: function(subgridId, rowId) {
var subgridTableId = subgridId + '_t';
jQuery('#' + subgridId).append('<table id="' + subgridTableId + '"></table>');
var subgridPagerId = subgridId + '_p';
jQuery('#' + subgridId).append('<div id="' + subgridPagerId + '"></div>');
$('#' + subgridTableId).jqGrid({colNames: ['Fecha','Importe'],
colModel: [{ name: 'Fecha' },
{ editable: true, editrules: { number: true }, formatter: 'currency', formatoptions: { prefix: '$' }, name: 'Importe' }
],url: '/Honorarios/DetailSubgrid?id=' + rowId, datatype: 'json', mtype: 'POST', pager: '#' + subgridPagerId,
prmNames: { id: 'HonorarioId' },
rowList: [10,15,20,25,30],
sortname: 'HonorarioId',
viewrecords: true,
width: 600,
height: '100%'}).jqGrid('navGrid', '#' + subgridPagerId,{ search: false },{ url: '/Honorarios/Update', closeAfterEdit: true },{ url: '/Honorarios/Update', closeAfterEdit: true },{ url: '/Honorarios/Delete' });
},
viewrecords: true,
width: 1000,
height: '100%'
}).jqGrid('navGrid', '#ClientesPager',{ search: false },{ url: '/Clientes/Update', width: 500, closeAfterEdit: true }, { url: '/Clientes/Update', width: 500, closeAfterEdit: true }, { url: '/Clientes/Delete' });
});
I need to pass the ClienteId parameter when a record is added or edited in the sub grid
This should be done using postdata?
something like
postData: {ClienteId: row_id}
the solution is using
editData: { ClienteId: rowId }
Tanks #tpeczek

How to get the Parent id from the subgrid rowId?

I am using a JqGrid and subgrid. I have to get the parent id from the subgrid rowId.
Kindly help me out in solving this..
I am pasting my code below.
//This is Grid
$("#DayEvents").jqGrid({
url: 'Event.asmx/GetDayForEvents',
datatype: 'json',
mtype: 'POST',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: PrepareGridPostData,
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
colNames: ['day', 'DayID'],
colModel: [{ name: 'Day', index: 'Day', editable: false, width: 550, align: 'center', sortable: false },
{ name: 'DayID', index: 'DayID', editable: false, width: 550, align: 'center', sortable: false, hidden: true }
],
rowNum: 10,
rowList: [5, 10, 15, 20],
// pager: "#pager2",
viewrecords: true,
gridview: true,
width: '100%',
autowidth: false,
shrinkToFit: false,
height: '331px',
// pgbuttons: true,
hoverrows: false,
//caption: 'Days',
subGrid: true,
subGridUrl: 'Event.asmx/GetSubGridDay',
subGridOptions: {
"plusicon": "ui-icon-triangle-1-e",
"minusicon": "ui-icon-triangle-1-s",
"openicon": "ui-icon-arrowreturn-1-e",
//expand all rows on load
"expandOnLoad": false
},
//This is Subgrid
subGridRowExpanded: function(subgrid_id, row_id) {
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id + "_t";
pager_id = "p_" + subgrid_table_id;
//alert(subgrid_table_id);
$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><a href=# id='AddSession' OnClick='addRow(\"" + subgrid_table_id + "\");'>add session</a><div id='" + pager_id + "' class='scroll'></div>");
//debugger;
jQuery("#" + subgrid_table_id).jqGrid({
url: 'Event.asmx/GetSubGridDay',
datatype: 'json',
mtype: 'POST',
cellEdit: true,
cellsubmit: 'clientarray',
onCellSelect: GridCellClick,
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: PrepareGridPostData,
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
colNames: ['session', 'start time', 'end time'],
colModel: [
{ name: 'SessionName', index: 'SessionName', width: 90, formatter: 'text', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]} },
{ name: 'StartTime', index: 'StartTime', width: 90, formatter: 'number', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]} },
{ name: 'EndTime', index: 'EndTime', width: 90, formatter: 'number', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]} }
],
rowNum: 10,
height: 'auto',
autowidth: true
});
}
});
Inside of callback function subGridRowExpanded you can use this variable which is initialized to the DOM of the grid (DOM of the ). So you can get id of the parent grid by this.id.
check for documentation of subGridRowExpanded

NO URL IS SET - error in jqGrid (Add, Delete dialog)

I've following Grid to display data, now when I want to add new record it gives the error 'NO URL IS SET'
$(document).ready(function () {
$('#PRGrid').jqGrid({
//url from wich data should be requested
url: '#Url.Action("BindData")?FillType=' + getFillType(),
//event for inline edit
onSelectRow: function (currentSelectedRow) {
if (currentSelectedRow && currentSelectedRow != $.lastSelectedRow) {
//save changes in row
$('#PRGrid').jqGrid('saveRow', $.lastSelectedRow, false);
$.lastSelectedRow = currentSelectedRow;
}
//trigger inline edit for row
},
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: ['Code', 'Name', 'No_Rooms', 'Dept_Code', 'Total_Items'],
//columns model
colModel: [
{ name: 'Code', index: 'Code', align: 'left', width: '120px', editable: true, edittype: 'select', editoptions: { maxlength: 25, dataUrl: '#Url.Action("GetRooms")',
dataEvents: [{
type: 'change', fn: function (e) {
var ret = $.ajax({
url: '#Url.Action("selectRoom")?id=' + $(this).val(),
async: false,
success: function (ret) {
$('#Name').val(ret.Name);
$('#No_Rooms').val(ret.qty);
$('#Dept_Code').val(ret.DeptCode);
$('#Total_Items').val(ret.Total_Items);}
});}
}]
}},
{ name: 'Name', index: 'Name', align: 'left', formatter: "text", width: '185px', editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
{ name: 'No_Rooms', index: 'No_Rooms', align: 'left', formatter: "text", width: '102px', integer: true, editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
{ name: 'Dept_Code', index: 'Dept_Code', align: 'left', formatter: "text", width: '78px', editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
{ name: 'Total_Items', index: 'Total_Items', align: 'left', formatter: "text", width: '82px', integer: true, editable: true, editrules: { required: true }, editoptions: { readonly: 'readonly'} },
],
//pager for grid
pager: $('#PRGridPager'),
//number of rows per page
rowNum: 5,
//initial sorting column
sortname: 'Code',
//initial sorting direction
sortorder: 'asc',
recreateForm:true,
//we want to display total records count
viewrecords: true,
//grid height
height: '100%'
});
$('#PRGrid').jqGrid('navGrid', '#PRGridPager',
{ add: true, del: true, edit:false, search: true },
{width: '330', url:'#Url.Action("InsertPRGridRecord")', closeAfterAdd: true },
{width: '330', url:'#Url.Action("DeleteGridRecord")'});
var dialogPosition = $(this).offset();
Problem arrise when I want to add or delete the record from the grid,
Here I've defined both the methods InsertPRGridRecord() and DeleteGridRecord(), but it gives the same error 'NO URL IS SET' at the time of submitting the data on Add Record or Delete Record dialog.
I think the problem exist because you use incorrect the parameters of navGrid. Your current code uses '#Url.Action("DeleteGridRecord")' as URL of "Add" and '#Url.Action("InsertPRGridRecord")' as URL of "Edit". The URL of "Delete" is not specified.

Resources