Knowledge Base
  • Introduction
  • Events and Actions
  • Action Panel
  • sending email
  • calling a SQL action from a client side js action
  • Accessing to translations form a server
  • Executing SQL statements from within an action
  • How to invoke a generic SQL statement defined through a SQL action
  • How to show a message dialog
  • checking for "undefined" values
  • How to add spaces to the right of a text
  • How to create a docx report and show it on the web browser Enterprise Edition only
  • How to get or set a value from the graphics control
  • How to invoke a generic SQL query defined through a business component
  • How to remove spaces to the left and right of a text
  • How to support multiple themes in a single application, accoding to a rule
  • How to set content to a Google Map linked to a grid or form
  • How to replace all occurences of a pattern from a text
  • Utility methods
  • Link auto login
  • Creation of a link for the first access of a new user without give the user a password and forcing
  • Forgot password
  • setting up default values from values coming from a filter panel
  • identifing the modified record after the alteration
  • enabling/disabling checkboxes in a grid
  • Filtering a Lookup
  • formatting a column
  • using checkboxes to select rows in grid
  • showing a summary row in grid
  • Disabling a toolbar button
  • Configuring grid exports
  • Adding filter conditions to a grid
  • Filtering the grid content from a tree
  • Filtering the tree content, starting from a filter panel linked to a grid
  • collapsing a panel
  • validating a lookup
  • accessing the authorizations set for a specific grid
  • How to design a web service
  • How to remotelly invoke an action or business component or perform a write operation through a Restf
  • how to feed a grid from a JS business component
  • converting a JS object to a JSON string
  • executing a query
  • passing parameters to a server side JS action
  • return value
  • scheduling and frequency
  • finding the right filter panel
  • checking out if a component has been defined
  • Deploying an application
  • Enquiring a table belonging to the Platform repository
  • Adding a where clause to a business component linked to grid
  • Integrating Mailchimp lists
  • Formatting a number as a currency value to use it inside an email template
  • sending email from a template
  • How to send an email
  • Error 'smtpHost' is empty
  • Linking two windows
  • How to open manually a window from another window
  • How to open manually a popup window
  • How to hide a panel in a window dinamically
  • How to manage folder panels
  • How to manage card panels
  • Predefined variables supported by Platform
  • Accessing the application parameters
  • Application Log
  • How to design a web service
  • How to import java classes in server
  • How to import java classes in server
  • How to dynamically set a value on a combo
  • 4WS.Platform
  • How to listen to events in a mobile HTML panel
  • Issues with HTTPS requests
  • How to manage row totals in grid
  • How to send to the UI a notification to execute code automatically
  • How to filter a chart by date interval
  • How to filter a grid by date interval
  • How to read a text or csv file and save data on the database
  • How to write text or csv files
  • Reading an xls file stored in the specified path
  • How to create a report with Jasper Report
  • How to customize the alert message content
  • Setting up a cluster
  • Uploading and downloading files
  • How to listen to user definition changes
  • How to auto-show a window from login
  • How to manage encrypted fields
  • How to change CSS settings for a grid row
  • Customizing a Tree Panel
  • How to execute complex queries on Google Datastore
  • Theme customization
  • Retrieve and send the log of a mobile app
  • Import Roles and Users
  • How to synchronize multiple Form panels in the same window
  • Anchor buttons
  • Properties of subpanels
  • Bulk import
  • How to display the data not found message in a grid
  • How to setup an LDAP based authentication
  • How to synchronize data from Datastore to BigQuery
  • How to synchronize data from Datastore to Google Spanner
  • How to synchronize data from Datastore to CloudSQL
  • Scrollable form list
  • How to setup SAML authentication
  • How to export data from BigQuery in streaming
  • Update Google Spreadsheet
  • How to setup OAuth2 authentication
Powered by GitBook
On this page
  • Settings colors
  • Settings totals reckoned on the server-side

Was this helpful?

How to manage row totals in grid

It is possible to add a row containing totals for each column, anchored at the bottom part of the grid. When scrolling grid, this row totals is still visible and locked to the bottom side.

In order to activate this row total, go to the grid definition panel and select the "row totals" check box. After doing it, a client-side javascript action is created and linked to the "Update summary row" grid event.

This action will be automatically invoked every time the data model changes, e.g. when reloading it.

When reloading a grid, the action is invoked for each column twice: when the model is cleared up and when the model has been completely loaded.

This action receives as input several js objects:

  • gridxxx - current grid, generating this event

  • colAttr - attribute name of the current column: this action is invoked for each column defined in the grid

  • total - a numeric value, corresponding to the current total for the current column

  • params - a javascript object containing a few attributes

    • css - css class name that can be applied for the current column

    • id - column index for the current column

    • style - style for the current column

    • attr_'ext:qtip - "Total no. of companies"' tooltip example

  • record.data: data to show in the last row

  • formattedValue: current total, reformatted with the same format of the values in the column

  • col - current column objects

The action should returns a numeric value (or string value) to show in the cell (in the totals row) related to the current column. If no return is provided, the cell remains empty.

A typical scenario is:

return formattedValue;

In this way, every column would provide a numeric value, even text type columns.

In order to limit the totals only for numeric type columns, the action could contain something like:

if (params.style.align=="right") // numeric type columns have a right alignment...
  return formattedValue;

Settings colors

It is also possible to dynamically set a foreground/background color to every cell, through the "params" js object, containing the "css" attribute, working at cell level.

If you have previously define a CSS class and save it in the <webcontext>/css/xtheme.css file, you can refer it in this class.

For example, suppose to define a CSS class named "red", whose purpose is to set a red background color. You could test the current value for a column and set a red color for cells having a negative value:

if (total<0) {
  params.css = "red"; // the CSS class name "red" must be defined in the xtheme.css file
}
return formattedValue;

Settings totals reckoned on the server-side

Please note that these totals are calculated based on data loaded in grid. That means the grid should be loaded completely, otherwise what shown only represents a partial total, related to the portion of data loaded in grid.

However, it is not recommended to load all data in grid, especially if the result set is composed on hundreds or more records. So a grid should always be loaded partially.

A consequence of that is the need to fetch "real" totals from the server-side. A way to do it is used a utility js function provided by Platform (available since 5.3.2 version). This method will invoke a server-side js action which has to reckon all required totals and then get them back to the js function, in order to populate the totals row.

This utility function has the following syntax:

summaryRow(grid,actionId,reqParams,colAttr,callback)

Required arguments are:

  • grid - the current, containing the total row

  • actionId - the id for the server-side action returning totals, one attribute for each column having a total

  • reqParams - optional parameters to pass forward to the server-side action; can be set to null

  • callback - js function invoked for each attribute; arguments passed to the function: callback(num, grid, colAttr)

An example of usage is as follows:

return summaryRow(
    gridxx,
    xyz, // actionId for the server-side js action
    {}, // req params
    colAttr,
    function(num, grid, colAttr) {
        if (colAttr=="docTotal")
          return num;
        else if (colAttr=="customerCredit") {
            if (num<0)
              params.css = "red";
            return num;
        }
    }
);

This function do all the job behind the scenes:

  • invokes the server-side js action once

  • gets back the js object and calls multiple times the callback

The constraint to respect for the server-side js action is to provide a js object as a return value, containing as many attributes as the ones defined for the columns of the grid: each attribute identifies a column in grid and provides the total for that column:

var obj = {
  docTotal: 123.50,
  customerCredit: -20
};
utils.setReturnValue(JSON.stringify(obj));

The callback function is helpful to manage the total number for each column: it can redefine the total, format it or set an additional CSS for thast cell, dynamically.

Note: summaryRow method is synchronous, i.e. it invokes the server-side to retrieve totals every time the grid is loaded and once got data, it shows data on the summary row.

Al alternative approach is using the asynchronous version, described below.

(From 6.0.2) The asynchronous utility function has the following syntax:

summaryRowAsync(grid,actionId,reqParams,colAttr,callback)

Required arguments are:

  • grid - the current, containing the total row

  • actionId - the id for the server-side action returning totals, one attribute for each column having a total

  • reqParams - optional parameters to pass forward to the server-side action; can be set to null

  • callback - js function invoked for each attribute; arguments passed to the function: callback(num, grid, colAttr)

An example of usage is as follows:

return summaryRowAsync(
    gridxx,
    xyz, // actionId for the server-side js action
    {}, // req params
    colAttr,
    function(num, grid, colAttr) {
        if (colAttr=="docTotal")
          return num;
        else if (colAttr=="customerCredit") {
            if (num<0)
              params.css = "red";
            return num;
        }
    }
);

From the point of view of the rendering, the difference with this second function is that data is retrieved in async way and, consequently, it can be rendered on the summary row later, once data has been returned from the server.

PreviousIssues with HTTPS requestsNextHow to send to the UI a notification to execute code automatically

Last updated 2 years ago

Was this helpful?