onRender slows my solution

I need to alternately colour the lines in a table view in a tabpanel, and show the selected record as a different colour.

My code (in a global) for onRender is this:

	var _rec = event.getRecord()
	if (event.isRecordSelected())    {
		   event.getElement().bgcolor = contacts_to_superuser.colour_selected;
	      event.getRenderable().fgcolor = '#000000'
	   } else if (event.getRecordIndex() % 2) {
		   event.getElement().bgcolor = contacts_to_superuser.colour_1;
	      event.getRenderable().fgcolor = '#000000'
	   } else {
		   event.getElement().bgcolor = contacts_to_superuser.colour_2;
	      event.getRenderable().fgcolor = '#000000'
	   }

Our users are complaining that adding records to the system is very slow (press new line and one is produced about 40 seconds later). I suspect the onRender is the cause, as when I turn the profiler on, it shows the onRender method being triggered hundreds of times (360 at most recent count). I am looking at a foundset of 6 records…

Am I doing the onRender correctly (it doesn’t make a difference whether I use the .bgcolor = myrelation, or .bgcolor = ‘#somecolour’)? Why would there be so many onRenders?

Thank you for any help with this

Bevil

It seems in the profiler that all the endless lines are all the elements in the form, one per record.

As a peripheral question, how do I colour JUST the background element? I don’t want all elements to be affected, just the row background…

Hi Bevil,
I think I had a similar issue & from what I can remember, your issue might be to do with you using the
contacts_to_superuser
relationship
I think you should be accessing it as
_rec.contacts_to_superuser.colour_selected
assuming that the onRender is happening in the contacts table

onRender if you have it attached to a form will fire for EACH element on your form, so if you have a complex form it will fire a lot.
You can just have specific onRender events only for the elements you actually want to do something on

With regard to bg row colour, can you use CSS style sheet which is recommended way??

Rafi

Hi Rafi

I thought that might be the case (after the Wiki says to not use any external code) so I tried a var get_superuser_colour_1 _2 _3 etc. at the beginning of the method, and replaced the relations within the onrender with my vars. No difference…

:(

onRender is evil. Don’t use if for tables generally and never for tables in web client. Use css for row coloring and change the style sheet at runtime for your SaaS preferences.

Just backing Rafi up :)

I would say that a onRowRender() event is badly needed in table view mode…
Fired after all column onRender() events (if present) of the row have been fired.

onRender is not evil, but very powerful, and YES you have to be careful because you can screw things up very quickly.

back the source of the problem:
@Bevil, what happens if you just remove the onRender, and add a record? (you say: you suspect, so you are not sure?)

Hi Harjo

This is linked to my same problem in the other thread. I thought it was onRender. I am not so sure now. The reason I suspected onRender was because the profiler in Servoy developer shows hundreds (360) onrender events when I add a line - however this mostly slows it down when the profiler is running, and the 360 is logged for each of the elements on the form.

My remaining issue with onRender, for which there seems to be nothing on the forum, is whether there is a way to get it to only render the bgcolor of the form element / body background. I don’t want to render all 360 elements (do I have to?) and also I don’t want to change the colour of some elements (a combobox for example also changes colour when my onRender is triggered.)

In short, the issue I thought with onRender seems to be part of a bigger issue, and onRender is possibly not the culprit.

What code are you using to add the line? You may be accidentally triggering screen redraws…

Hi Christian

This is my new line code:

function new_line_using_group()
{
	var sql_query = "SELECT MAX(estimate_item_id) FROM line_items WHERE line_items.sales_id = ? AND line_items.main_group = ? AND line_items.hidden_from_estimate <> 1";	
	
    var vDataSet = databaseManager.getDataSetByQuery(databaseManager.getDataSourceServerName(controller.getDataSource()), sql_query, [forms.sale_master.salesid,globals.g_main_group], 1);
    
    var vthehighestvaluenumber = vDataSet.getValue(1,1);    
    
    if ( globals.g_main_group == 'new group' || globals.g_main_group == 'all groups' || globals.g_main_group == 'ready to invoice') {
	        var thePressedButton = plugins.dialogs.showErrorDialog('No group', 'Please create or choose a group before adding a line','OK');
	        return;
	       }
	      
    else {
        foundset.newRecord(true);
        main_group = globals.g_main_group;
        sales_id = forms.sale_master.salesid;
        contacts_id = forms.sale_master.contacts_id;
        company_foundset_creator = globals.g_my_group
        complete = 0
		hidden_from_estimate = 0
        if ( vthehighestvaluenumber ) {            
            estimate_item_id = vthehighestvaluenumber + 10;
            }
        else{
            estimate_item_id = 10;
            }
       
        
        databaseManager.saveData();
    }
}

Now this discussion is on two places!
keep it central please ;-)

Initially I thought it was two separate problem….

:)

Sometimes Servoy has trouble working out which order to save stuff in…

Try helping Servoy by adding:

databaseManager.saveData(foundset.getSelectedRecord());

just before

databaseManager.saveData();

Also is the found set by any chance based on company_foundset_creator?

bevil:
In short, the issue I thought with onRender seems to be part of a bigger issue, and onRender is possibly not the culprit.

This is simple to check…turn onRender off. Run faster?