-1

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.

John Schultz
  • 672
  • 1
  • 10
  • 29

1 Answers1

1

I see a spelling mistake of undefined. Could that be the cause? I'm not sure.

Tahir Ahmed
  • 5,687
  • 2
  • 17
  • 28
  • That was it. Why is it always the simplest of things :). Thank you. – John Schultz Jul 04 '15 at 20:47
  • Oh we all do that. Can I just propose one thing though? You seem to be doing the same thing over and over again. With all the three rows, you are doing the same thing. I suggest you to extract a function out of them. Reusability you know. – Tahir Ahmed Jul 04 '15 at 20:57
  • 1
    Thats the next thing I am going to do. Just needed a way to differentiate between which grid called the add new account dialogue. This was just a quick and dirty method first, then comes the beautification process. :) – John Schultz Jul 04 '15 at 21:05