Event handlers & helper methods for a Kendo Grid
The second solution has two main improvements:


Fewer lookups. Every time you call your original getSelectedId method,
the lookup for $("MainGrid").data("kendoGrid"); is performed again.
The 2nd version caches this in gridHandler.mainGrid -- only one lookup.
The same goes for subGrid.
More compact. For example the subGrid local variable here was not particularly useful:


function hideSubGrid() {
    var subGrid = $("SubGrid").data("kendoGrid");

    subGrid.addClass("hidden");
}



It would have been simpler and more natural this way:

function hideSubGrid() {
    $("SubGrid").data("kendoGrid").addClass("hidden");
}

Reduced namespace clutter. By putting the methods in a gridHandler, you don't have many methods lying around in the global namespace, they are all neatly inside gridHandler.