-
-
Save cklann1/ad09101e9c87aff65b6a8651ef0b0484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showRow(doc){ | |
var cache = getCache_(); | |
try { | |
// if cache is set and id matches handle open row for editing | |
if (cache.id && cache.id === doc.getId()){ | |
doc.toast("Opened on row for editing..."); | |
var sheet = doc.getSheetByName(cache.sheet); | |
if (sheet != null) { | |
if(cache.row){ | |
sheet.hideRows(2, sheet.getLastRow()-1); // hide all the rows | |
sheet.showRows(cache.row); // show row | |
if (cache.header > 0){ // if header set show it | |
sheet.showRows(1, cache.header); | |
} else { | |
sheet.hideRows(1); | |
} | |
doc.setActiveRange(sheet.getRange("B1")); // set to row one first to keep above fold | |
doc.setActiveRange(sheet.getRange("A"+cache.row)); | |
} | |
PropertiesService.getUserProperties().setProperty("id", ""); | |
} | |
// tried CacheService but seemed unreliabe | |
//CacheService.getUserCache().removeAll(KEYS) | |
} else { | |
// default to showing all rows .. bit of a hacky way of doing it | |
var sheets = doc.getSheets(); | |
for(var n in sheets){ | |
sheets[n].showRows(1, sheets[n].getLastRow()); | |
} | |
doc.toast("Showing all rows..."); | |
} | |
} catch(e) { | |
PropertiesService.getUserProperties().setProperty("id", ""); | |
doc.toast("Error on " +e.lineNumber + " "+e.message); | |
} | |
} | |
function getCache_(){ | |
// tried CacheService but seemed unreliabe | |
// return CacheService.getUserCache().getAll(KEYS); | |
return PropertiesService.getUserProperties().getProperties(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment