i have this code and i have a little problem, when i edit, i have the rowid value in codSelected to send to my handler, its stored by onSelectRow event. If I edit a row, works well, but if edit one and inmediately i want to add a new one, i need this value (_codSelected) null, but it has the same value of the last edited row. I know that i can use addfunc in the pager, but if i use this, i cant use the popup window that jqGrid use by default.
Thanks.
$("#list").jqGrid({
url: '/modulos/mantenimiento/Proveedores.ashx',
datatype: 'xml',
mtype: 'GET',
colNames: ['Codigo' //Some more colnames and colmodels]
colModel: [
{ name: 'Codigo', index: 'PRg_Codigo', edittype: 'select',
editable: true, editrules: { edithidden: false }, editoptions:
{ size: 30, dataUrl: '/modulos/mantenimiento/grupoProveedores.ashx?
oper=selectAllGroups' }, sortable: true }
],
onSelectRow: function (rowid) {
_codSelected = rowid;
},
ajaxSelectOptions: {
data: {
codSelected: function () {
return _codSelected;
}
}
}
});
jQuery("#list").jqGrid('navGrid', '#pager', {
alerttext: "Seleccione un Servicio.",
add: true, addtitle: "Crear nuevo Servicio",
del: true, deltitle: "Eliminar Servicio",
edit: true, edittitle: "Modificar Servicio",
search: false, searchtitle: "Búsqueda",
refresh: true,
cloneToTop: true
},
{ width: 360, resize: false, closeAfterEdit: true, recreateForm: true,
viewPagerButtons: true, afterComplete: muestraResultadoOperacion },
{ width: 360, resize: false, closeAfterAdd: true, recreateForm: true,
viewPagerButtons: true, afterComplete: muestraResultadoOperacion },
{},
{ closeAfterSearch: true, closeOnEscape: true });
I am not sure that I understand full your requirements.
First of all
_codSelectedseems is the same as the value of internalselrowoption of jqGrid. You can use$("#list").jqGrid("getGridParam", "selrow")to get therowidof the last selected row. If you want to initialize the_codSelectedvariable to the value of the current selected row only in case of Edit dialog and set it tonullin case of Add dialog you can do this inside of beforeInitData callback. ThebeforeInitDatacallback for Add dialog can set_codSelectedtonulland the same callback for Edit dialog can use_codSelected = $(this).jqGrid("getGridParam", "selrow");. It should solve your problem.UPDATED: To clear my suggestion I decide to post the following code: