onRender question

Hi all,

I have a form in table-view.

So I would to change the background color and the fgcolor if specific conditions are sotisfied.

If I have for example:
1 - a form in table-view with three columns: date,myname,mysurname
2 - in this form I have 40 records and I want to change the bgcolor and fgcolor only of the “date” field but just for the line in wich the “date” is less than “Date.now()”.

I’ve tried to use the “onRender” properties of the “date” field but it has this behavior:

If I select a line with date<Date.now(), then ALL the column changes bgcolor and fgcolor.
If I select a line with date>Date.now(), then ALL the column return to its bgcolor and fgcolor.

onRender seems to work with “onRecordSelection” event and seems to work on the entire column instead of the single field (replied N times).

So my question is: Does exist a way to change bgcolor and fgcolor into a form in tableview but just of one specifc field (for example the field in column 1, line 4)?

like this:
[attachment=0]result_woulded.png[/attachment]

Thanks

Riccardo

result_woulded.png

You can narrow down the element you want highlited by testing for the particular elements’ dataprovider or name, then apply the changes you want accordingly.

var _record = event.getRecord() ;
	if (_record && _record.date > Date.now() && event.getRenderable().getName() == 'myname') {
		event.getRenderable().bgcolor = '#ff0000'
	}

or: 

	if ( _record && _record.date > Date.now() &&  event.getRenderable().getDataProviderID() == 'mydataprovider') {
		event.getRenderable().bgcolor = '#ff0000'
	}

You may want to test for the existence of the record as per this thread: https://www.servoy.com/forum/viewtopic.php?f=22&t=18630

Hi Matt!

Thanks for the reply but I do this (this look like very similar to what you’ve suggested):

var _record = foundset.getRecord()
	var _date = _record.data_scadenza
	if(_date==null)
		return
			
	if(_date.valueOf()<Date.now().valueOf()){ //if the document is expired
		event.getRenderable().bgcolor = "#ff0000"
		event.getRenderable().fgcolor= "#ffffff"		
	}

And I obtain the behavior I’ve described before: If I select the line with the date Expired then all the column takes the red background.
This code seems to change “father” field of the column instead of single cell.

You should get the record from the event, not from the foundset.
Also make sure to set the color if the document is not expired, because otherwise it will not change the color if the data_scadenza changes.

For example:

function onRender(event) {
	var _record = event.getRecord();
	var _element = event.getRenderable();
	
	var _date = _record.data_scadenza

	if (_date && _date < Date.now() && _element.getDataproviderID() == "data_scadenza") { //if the document is expired
		_element.bgcolor = "#ff0000"
		_element.fgcolor = "#ffffff"
	} else {
		_element.bgcolor = "#ffffff"
		_element.fgcolor = "#000000"
	}
}

Joas, Matt

Now I’ve solved, the main problem was that I was taking the record from the foundset and not from the event!

Just for report my result:

Joas, If I specify an “else” case, I see that Servoy overwrite the css-odd/even functionality.
If I don’t the “else”, the css works (and the specific cell is properly formatted)!

That to all for the help!

Riccardo