I have a onRender function for a table view form, because I would like to display all records with the column flag_int (integer) value 1 in a specific fgcolor. The code for this is:
it seems to be not working on Table view (locked) forms. The event.getRecord() gives null back.
Btw, this is what the tooltip of the JSRenderEvent.getRecord(): JSRecord in the developer says…
Do I set the form property to List view, the onReder event is working as expected.
Is there a way to get this working also on a Table view form?
EDIT
I tried your solution Robert (record && record.flag_int == 1) and this is working on my Table view form!
I am glad it’s working (as in not giving errors) for you. But you say that with a table view the JSRenderEvent doesn’t return a JSRecord object but with a listview it does. That sounds to me like a bug and you should report it as such.
What Servoy version is this in ?
tgs:
And indeed the onRender function is now working without errors. Curious or, because of the null return?
It doesn’t error because now you check if there is a value in your record variable.
if ( record ) {
// I am not null, zero (0), false, undefined or an empty string ('').
} else {
// I have a value (other than 0 or false or '')
}
So using if (record && record.flag_int == 1 ) will make the condition fail before it tries to access record.flag_int and therefor won’t generate an error.
I understand this, but I thought in Table view the onRender event return always null? Why is it working (coloring the fgcolor of the flagged records) because the event must return anything and not null?
event.getRecord() does not always return null, in a table-view, but CAN return null.
I talked to Johan about this a while ago, and this is because the onRender is much triggered, (also over elements, that do not have recordObject attached)
and his advice was also, to ALWAYS check the recordObject first.
So does this mean that the ability I had to highlight certain records in the old form bgcolour property has now been lost.
I wanted to show certain “cancelled” records with a red background. The only way i can do this is by referring to a record field and it seams the onRender function cannot do this like the old bgcolour property used to do?
I needed the same functionality as well using a “return” calculation / virtual column and was getting the same “Type error: Cannot read…” error. After searching the forum and coming across this post i have it working now. Curious as to why, i stepped through it in the debugger and the reason (one of, anyway) it is necessary to test for a record object is that the onRender event first fires for the form object itself and therefore the event.getrecord() is null (and Index = -1 ). So as reported above testing for the record is necessary. After that the onRender is fired for the table view rows/records and the results are as expected.
The Point being to answer David’s question: No, you don’t lose the functionality from bgcolour property. Just done in a slightly different way.