I have three jqxgrids that call the same function to create a new account (which is a jq ui dialogue). What is the easiest or best way to differentiate between which grid was called.
My code:
$("#divNewAccountDetails").dialog({
autoOpen: F,
modal: T,
title: "New Account",
width: 600,
close: function () {
},
buttons: {
"Save & Close": function () {
$(this).dialog("close");
var _Object, indexes, _row1, _row2, _row3;
_Object = $("#jqxAccountDropdownGrid");
indexes = $(_Object).jqxGrid('selectedrowindexes');
for (var index in indexes) {
_row1 = $(_Object).jqxGrid('getrowdata', index);
if (typeof _row1["AccountName"] !== "undefind") {
if (_row1["AccountName"].toString().toLowerCase() === "new") {
alert("Account");
$(_Object).jqxGrid('clearselection');
break;
}
}
}
_Object = $("#jqxPurchaseAccountDropdownGrid");
indexes = $(_Object).jqxGrid('selectedrowindexes');
for (var index in indexes) {
_row2 = $(_Object).jqxGrid('getrowdata', index);
if (typeof _row2["AccountName"] !== "undefind") {
if (_row2["AccountName"].toString().toLowerCase() === "new") {
alert("Purchase Account");
$(_Object).jqxGrid('clearselection');
break;
}
}
}
_Object = $("#jqxSalesAccountDropdownGrid");
indexes = $(_Object).jqxGrid('selectedrowindexes');
for (var index in indexes) {
_row3 = $(_Object).jqxGrid('getrowdata', index);
if (typeof _row3["AccountName"] !== "undefind") {
if (_row3["AccountName"].toString().toLowerCase() === "new") {
alert("Sales Account");
$(_Object).jqxGrid('clearselection');
break;
}
}
}
},
Cancel: function () {
$(this).dialog("close");
}
}
});
So basically the Grids are bound to a column change and when that columns value is "new"
, the script triggers the dialogue (code above). What is happening is that when I click the Save & Close
button, I get "Uncaught TypeError: Cannot read property 'toString' of undefined"
. What I do not understand is that I am using a logic test to check for undefined and it appears to be executing the if block anyway which it shouldn't.