Finding categories for a Selected Item

3.98K viewsScripting
0

The lack of this ability is a serious irritation.

It is possible to parse the string returned by .[i:16vml1ki]SelectedCells[/i:16vml1ki]. Ben has provided a couple of examples:
[url:16vml1ki]http://forum.quantrix.com/viewtopic.php?f=27&t=828[/url:16vml1ki]
[url:16vml1ki]http://forum.quantrix.com/viewtopic.php?f=27&t=951[/url:16vml1ki]

I needed a more general version – this takes any selection in a Table View and returns the view and categories related to that item:

[code:16vml1ki]String errMessage = ‘Must select item(s) within body of a Table View’

String selected = model.selectedCells
if (selected==null) { alert errMessage; return }

List s1 = selected.split(‘::’)
String viewName = s1[0].substring(2,s1[0].length()-1)
view = matrixViews[viewName]
if (view==null) { alert errMessage; return }

def matcher = ( s1[1] =~ /(d+), (d+)/ )
int row = matcher[0][1].toInteger() -1
int column = matcher[0][2].toInteger() -1
println "$view Row: $row, Column: $column (converted to zero base)"

rowCats = view.rowTrayCategories.asList()
println "rowTrayCategories: ${rowCats*.name} lengths: ${rowCats*.items*.size}"
columnCats = view.columnTrayCategories.asList()
println "columnTrayCategories: ${columnCats*.name} lengths: ${columnCats*.items*.size}"
filterCats = view.filterTrayCategories
filterItems = filterCats.collect{view.getFilterItem(it).name}
println "filterTrayCategories: ${filterCats*.name} selected: ${filterItems.join(‘:’)}"

List parseCategories( Integer position, List cats) {
List catsSelected = []
int r1 = position
for (c in cats.reverse() ) {
int r2 = r1.mod(c.items.size)
catsSelected << c.items[r2]
r1 /= c.items.size
}
return catsSelected.reverse()
}

List allCats = parseCategories(row, rowCats)+parseCategories(column, columnCats)+view.filterTrayCategories.collect{view.getFilterItem(it)}
println "
Selected item: ‘$view.name’::" + allCats*.name.join(‘:’)
[/code:16vml1ki]
The parsing relies on the fact that a View name is hyphenated and thus quoted. More complex regular expressions could handle this, but I preferred the simple split and RegEx just to extract the (first) pair of numbers. If a range is selected then the script identified only the first item in the range.

0

Thank you for the note. We actually talked about this in today’s development stand up meeting. I am hopeful a way to address this will be available in our Q1-2015 desktop release.

You are viewing 1 out of 1 answers, click here to view all answers.

Latest Questions