...
Starting from Servoy 6 there is a new onRender event added to Forms, Portals and Elements. The aim of this event is to allow changing display properties of supporting components just before they are shown or updated.
On Form and Portals the event is fired not only for the Form/Portal itself, but also for all the elements the standard Servoy Elements on the Form/Portal, if the element does not have its own onRender event handler. The . The Form/Portal level onRedner event will not fire for beans.
The onRender event handler is called with a parameter of type JSRenderEvent, that provides the following functions:
Here is a sample usage for alternative row coloring :
...
Any updates made in the onRender event to the rendering object are valid until the onRender event is called again on the same object: when the Renderable object goes into the onRender event the object is as it is defined in the SolutionModel. This means that changes made in the previous onRender cycle are not there anymore, but also any scripted changes to the element at Runtime are not there anymore.
Example use: Making negative values in a column red
Code Block |
---|
/** * Called before the form component is rendered. * * @param {JSRenderEvent} event the render event */ function onRender(event) { /** @type { if(event.getRenderable() instanceof RuntimeComponent) { JSRecord<db:/udm/orders>}*/ var rec = event.getRecord() if (rec.amt_tax == 0) { event.getRenderable().bgcolorfgcolor = '#ff0000#ff6600'; } else else if (rec.amt_tax < 0) { event.getRenderable().bgcolorfgcolor = '#00ff00#ff0000'; } } |
Using onRender you can replace rowBGColorCalculation events as
you can change the display of row elements just before they are
displayed. This is why, rowBGColorCalculation has been deprecated in
Servoy 6
...
About performance: The onRender event will be fired often., It's therefor advised to keep the logic inside the onRender event handler method as optimized as possible, for quick execution. It's advised to refrain from calling any code outside the API of the JSRenderEvent or the Renderable class.
Inheritance model
The Inheritance model of Servoy has been enhanced to allow:
...