Last active
November 17, 2019 07:53
-
-
Save mhawksey/743a7d7f56914090f980efdce20192c5 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.hideRow(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
Thanks for the example, Martin! Updated to fix minor syntax on row 16 (throwing an error on hideRow()).