I have a jqGrid Treegrid defined as below:
$('#MyGrid').jqGrid({
colNames: ['Id','Nome','Nivel','Combo',''],
colModel: [
{ hidden: true, name: 'Id' },
{ editable: true, name: 'Nome' },
{ hidden: true, name: 'Nivel' },
{ name: 'Combo', editable: true, edittype: 'select',
editoptions: {
buildSelect: createSelectList ,
dataUrl: '/Home/GetCombo' // <-- to this controller, I want
// to send the id of the row edited to load custom items
// in select object
}},
{ formatter: 'actions', formatoptions: { keys: true },
resizable: false, search: false, sortable: false,
width: 60, viewable: false, name: 'actions' }
],
cellEdit: true,
url: '...',
datatype: 'json',
editurl: '...',
jsonReader: {
repeatitems: false,
id: 'Id',
subgrid: { repeatitems: false }
},
mtype: 'POST',
gridComplete: function() { myOnGridComplete(); },
ajaxSelectOptions: {
data: {
tempid: function () {
// !!! the next line always returns null
return $('#MyGrid').jqGrid('getGridParam', 'selrow');
}
}
},
prmNames: { npage: 'npage' },
rowNum: -1,
ExpandColClick: true,
ExpandColumn: 'Nome',
treeGrid: true,
treeGridModel: 'adjacency',
width: 700,
height: '100%'
});
My goal is to send the current row ID to the server, but when I use $('#MyGrid').jqGrid('getGridParam', 'selrow') I always get a null value.
I already read this posts but none of them solve my problem:
Any sugestions?
tks in advance!
Update 1:
The TreeGrid bind is ok. The real problem is when I click the Edit Button in the leaf node. In this event, I want to send additional data to the server.
I tried to accomplish this using the ajaxSelectOptions
, but this command always returns null: $('#MyGrid').jqGrid('getGridParam', 'selrow')
Workaround
This is a workaround that I did before Oleg's help:
Step 1: Create a hidden field in the HTML
Step 2: In my myOnGridComplete function, I set a click event to the edit button:
function onGridAjusteDTOComplete()
{
$('#MyGrid').find('span.ui-icon-pencil').each(function() {
$(this).click(function(){
var rowID = $(this).parents('tr').attr('id');
// !!! the next commented line not work in my case
// $('#MyGrid').jqGrid('setSelection', therowid );
$('#myHiddenField').val(rowID); // <-- this works
});
});
}
Step 3: Get the rowID
from the hidden field in the ajaxSelectOptions
:
ajaxSelectOptions: "{type: 'GET', contentType: 'application/json; charset=utf-8',dataType: 'json',cache: false, async:false, data: {id: function () { return $('#myHiddenField').val(); }}}"
Solution
See the solution provided by Oleg below. It's just amazing. Thank you Oleg.