If your UX allows record navigation then it seems to me it will be quite a mess to update the grids and then cancel the navigation if there is any type of error saving the grids.
In my app I had one main grid and just two linked grids. One of the linked grids was updateable, the other was read-only. It was are too much effort trying to ensure the main grid told the child grid to update when the user navigated the main grid or otherwise did something requiring the data to be saved. The process was slow running and difficult to program. In the web browser you never know what sequence things will run in. So, there was all kinds of error checking I had to throw into the code. Eventually, I ripped out the two child grids and now call them as modal popups -- life is so much simpler now and people don't mind viewing or updating data in the popups instead of on the main grid.
Perhaps I go overboard on error checking, but I believe all of the error checking you see in the following code was put their because it was an error condition that came up in trying to test and develop the code. The only purpose of the following function is to tell one linked grid to save its data: !!!
Code:
function SaveLinkedGridComments() { // ** Comments now in modal popup, not Linked Grid, so following is no longer used. // See if linked grid exists yet, and if it is dirty then flush changes to disk var gr = {grid.object}; if(typeof gr != 'undefined') { if( '_linkedGrids' in gr) { if(gr._linkedGrids['LINKCMNT'] != undefined) { if(gr._linkedGrids['LINKCMNT'][0] != undefined) { var linkedCMNT = window[gr._linkedGrids['LINKCMNT'][0] + '_GridObj']; if(linkedCMNT != undefined) { var cmnt_dirty = false; if('_isDirty' in linkedCMNT) { if(linkedCMNT._isDirty) { cmnt_dirty = true; } else { cmnt_dirty = false; } } else { alert('Unexpected error: flag1 not found!'); } var cmnt_dirty2 = false; if('_getGridVariables' in linkedCMNT) { var linkedCMNTGrid = {}; var linkedCMNTDtl = {}; linkedCMNT._getGridVariables(linkedCMNTGrid,linkedCMNTDtl); if(linkedCMNTGrid.isDirty) { cmnt_dirty2 = true; } } else { alert('function _getGridVariables not found'); } if( cmnt_dirty != cmnt_dirty2 ) { alert('Unexpected error: Change detection flags not equal! Flag1 = ' + cmnt_dirty + ' Flag2 = ' + cmnt_dirty2 ); } if( cmnt_dirty == true || cmnt_dirty2 == true ){ linkedCMNT.submitGridPart(); // SUBMIT COMMENT DATA } } else { alert('Unexpected error: Linked Detail Grid not found for Comment Area!'); } } else { alert('Unexpected error: Linked Comment Area Not Found!'); } } else { alert('Unexpected error: Linked Section Not Found!'); } } else { //--- Removed linked grids in favor of popups // when grid first loads the linked grids have not been attached yet. } } else { alert('Unexpected error: grid object not defined - {grid.object} '); } } // End SaveLinkedGridComments()
Leave a comment: