Executing Javascript with low/high priority

In this example you learn about executing javascript with Application::executeJsFunction() and Application::executeSelectorFunction() with different priority levels.

You can execute JavaScript using one of three priority-levels: Application::PRIORITY_LOW , Application::PRIORITY_STANDARD and Application::PRIORITY_HIGH Scripts with higher priority-level will be placed in the javascript execution-queue before scripts with lower ones and scripts with equal priority level are executed in the order you send them.

QCubed task order:

  • Render/update html
  • Execute JavaScript functions with Application::PRIORITY_HIGH
  • Execute QActions attached to controls with Events
  • Execute JavaScript functions with Application::PRIORITY_STANDARD
  • Execute JavaScript functions with Application::PRIORITY_LOW

Take a look at the example below. By clicking on one of the buttons the datagrid gets updated and an alert box will show up. Try clicking on buttons of both rows and look at the different update-behaviour.
The interesting code resides in the methods renderButton_Click and renderLowPriorityButton_Click

In these methods the datagrid is marked as modified (render it again, including all the buttons), some JavaScript alert boxes will show up and the color of the buttons changes due to adding a css class via JavaScript. The parameter Application::PRIORITY_LOW forces the script to be executed after all scripts with higher priority.

When the buttons are (re)rendered they get their standard color applied (and the JavaScript returned by GetEndScript is executed again). If you hit a update & low priority alert button the alert boxes have low priority, the JavaScript for adding the new css class is executed before the alerts show up and the color is changed immediately. When hitting a update & alert button the color will be changed after the alert boxes show up because all scripts are executed with standard priority.

Strategies for executing Javascript

The Application::executeJsFunction(), Application::executeSelectorFunction() and Application::executeControlCommand() functions are available to use invoke javascript in a number of ways. If these are not adequate, we recommend you put your javascript in a file, and invoke that javascript using one of the above functions.
Name Start standard priority javascript Start low priority javascript
row1
row2
row3
row4
row5
row6
row7
row8
row9
row10