Reputation: 967
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 });
Upvotes: 0
Views: 2604
Reputation: 221997
I am not sure that I understand full your requirements.
First of all _codSelected
seems is the same as the value of internal selrow
option of jqGrid. You can use $("#list").jqGrid("getGridParam", "selrow")
to get the rowid
of the last selected row. If you want to initialize the _codSelected
variable to the value of the current selected row only in case of Edit dialog and set it to null
in case of Add dialog you can do this inside of beforeInitData callback. The beforeInitData
callback for Add dialog can set _codSelected
to null
and 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:
var _codSelected = null;
// ...
// here should be the definition of jqGrid where you removed
// the current code of onSelectRow which changes _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,
beforeInitData: function () {
// set _codSelected in case of Edit operation
_codSelected = $(this).jqGrid("getGridParam", "selrow");
},
viewPagerButtons: true, afterComplete: muestraResultadoOperacion },
{ width: 360, resize: false, closeAfterAdd: true, recreateForm: true,
beforeInitData: function () {
// clear _codSelected in case of Add operation
_codSelected = null;
},
viewPagerButtons: true, afterComplete: muestraResultadoOperacion },
{},
{ closeAfterSearch: true, closeOnEscape: true });
Upvotes: 1