I've got a jqGrid along with a jquery UI button toolbar. My toolbar consists of View & Edit Mode. In my jqGrid onSelectRow I check edit mode with method isInEditMode. This returns true if the button with ui-active-state is edit button.
My grid seems loads correctly, and hover classes turn on/off as a drag my mouse over the rows. If I'm not in edit mode and click a row it does other functionality, which is correct. But when isInEditMode returns true it only seems to allow onSelectRow to fire ONCE.
Many thanks for all the help.
var lastselTsg;
grid.jqGrid({
colNames: ['BudgetId', 'BudgetAccountId', 'Account #', 'Name', 'Cost', 'StaticRowId', 'SortOrder'],
colModel: [
{ name: 'BudgetId', index: 'BudgetId', hidden: true, edithidden: true },
{ name: 'BudgetAccountId', index: 'BudgetAccountId', hidden: true, edithidden: true },
{ name: 'AccountNumber', index: 'AccountNumber', sortable: false, width: 70 },
{ name: 'BudgetName', index: 'BudgetName', sortable: false, width: 230, editable: true, edittype: 'text', editoptions: {
defaultValue: "",
dataInitInit: function (el) {
var value = $(el).val();
value = value.replace("<strong>", "");
value = value.replace("</strong>", "");
$(el).val(value);
$(el).focus();
if (value == "") {
$(el).remove();
return false;
}
}
}
},
{ name: 'TotalCost', index: 'TotalCost', sortable: false, formatter: totalCurrencyFormatter, width: 100 },
{ name: 'StaticRowId', index: 'StaticRowId', sortable: false, hidden: true, edithidden: true },
{ name: 'SortOrder', index: 'SortOrder', sortable: false, hidden: true, edithidden: true }
],
pager: pager,
pgbuttons: false,
pginput: false,
rowlist: [],
sortname: 'SortOrder',
rowNum: 99999999,
sortorder: "asc",
datatype: "json",
viewrecords: true,
url: url + "GetLoad",
editurl: url + "SaveGrid/",
loadComplete: function (data) {
},
onSelectRow: function (rowId) {
if (isInEditMode(budgetId)) {
if (rowId && rowId !== lastselTsg) {
grid.jqGrid('restoreRow', lastselTsg);
var rowData = grid.jqGrid("getRowData", rowId);
if (rowData != undefined && rowData != null) {
console.debug("entering edit mode");
grid.jqGrid('editRow', rowId, true, '', '', url + 'SaveTopSheet', {
budgetAccountId: rowData.BudgetAccountId
},
function(rowid, response) {
console.debug("aftersave: reloadGrid");
grid.trigger("reloadGrid");
}, '', function(rowid, reuslt) {
console.debug("after restore: reloadGrid");
grid.trigger("reloadGrid");
});
}
lastselTsg = rowId;
}
} else {
var getRowData = $("#baseTopSheetGrid" + budgetId).jqGrid('getRowData');
var rowData = getRowData[rowId - 1];
onSelectGridRow(rowData);
}
},
gridComplete: function () {
var ids = grid.jqGrid('getDataIDs');
var getRowDa开发者_如何学Gota = grid.jqGrid('getRowData');
if ($.isFunction(budgetGridLoadComplete))
budgetGridLoadComplete(getRowData);
}
}).navGrid(pager, { edit: false, add: false, del: false, search: true });
The else
part inside of onSelectRow
event handle looks like a little strange. You should better not call onSelectRow
inside of onSelectRow
and the usage of getRowData
inside of the same else
code fragment seems me also wrong (the rowId
should be parameter of the function).
精彩评论