Method names correspond to the form events of whatever table view you want this to work on. 20 second video of this in action here:
http://www.youtube.com/watch?v=ZMtXLAIr6jIWorks great in web client -- a little dodgy in smart client as I didn't spend any time with it fine tuning. Still lodge a feature request with Servoy. One line of code as compared to all this....
The real value of this exercise for us was figuring out that code in the onRender event can be controlled above and beyond the standard event states via form variables. Might come in handy someday.
- Code: Select all
/**
* Track last record index.
*
* @type {Number}
*
* @properties={typeid:35,uuid:"A59AE8F4-8C19-4E39-ACC9-B2DB24E1A2AB",variableType:4}
*/
var _index = null;
/**
* Track first show state of form.
*
* @type {Number}
*
* @properties={typeid:35,uuid:"C737D741-9579-4C6D-9A2A-3A25B5AE60D7",variableType:4}
*/
var _firstShow = null;
/**
* @properties={typeid:24,uuid:"B9BFB294-B3A8-4C12-A2E2-6C227BDC25AB"}
*/
function onShow(firstShow, event) {
// if table in related form, onRecordSelection event of parent form should
// set these same form variables to same initial values
_firstShow = 0
_index = 1
}
/**
* @properties={typeid:24,uuid:"94ABDB15-1D59-47AA-BE2F-6392C3CE18A2"}
*/
function onElementFocusLost(event) {
_index = controller.getSelectedIndex()
}
/**
* @properties={typeid:24,uuid:"13BA49DC-4B7D-45AF-913A-80ED8AD71E5B"}
*/
function onElementFocusedGained(event) {
if ( !_firstShow ) {
// setDesignMode() forces full UI redraw in web client so only do if
// if clicking same record
if ( controller.getSelectedIndex() == _index ) {
// hack to force onRender to fire when selecting a record that is already
// the current index
// (onRecordSelection event doesn't fire in this case...ergo, onRender doesn't fire)
controller.setDesignMode(true)
controller.setDesignMode(false)
}
_firstShow = 1
}
}
/**
* @properties={typeid:24,uuid:"4F331175-1E08-415A-88B7-1BFD59D05D2D"}
*/
function onRender(event) {
// event that overrides form css for selected
// only fire if first time (tracked in form variable: _firstShow)
if ( !_firstShow && event.isRecordSelected() ) {
event.getRenderable().bgcolor = '#ffffff' // non-selected color
}
}