Offline Data Workflow
The offline data load functionality can be implemented in the JavaScript file using the Canvas Widget Event Handler (CWEH). Canvas provides a simple method for loading offline data using the CWEC.BEFORE_DATA_LOAD event of CWEH. The CWEC.BEFORE_DATA_LOAD event can be used to process the data on the client (browser) before the data is rendered on the grid in the application. For example, CWEC.BEFORE_DATA_LOAD event can be used to update the grid data based on the result of some other activity or response from a Ajax call or a web service.
As shown in the workflow illustration, the offline data load functionality checks the JSON object returned by the app layer during app data loading. If the JSON object is null, and if offline data is provided in the CWEC.BEFORE_DATA_LOAD event, the offline data is displayed on the mobile application. If no data is provided in the CWEC.BEFORE_DATA_LOAD event, a message indicating that no data exist is shown. If the JSON object is not null, the remote data is loaded on the mobile application.
The value of the dataMerge is then checked, based on which local and remote data are either merged OR the local data is overridden with remote data. If dataMerge is set to true and if the mentioned unique column is present in the local and the remote data, then the local data will be overridden with the remote data. If dataMerge is set to true and if the unique column is not present, then the remote data will be appended to the local data. The CWEC.AFTER_DATA_LOAD event is triggered after loading data on the mobile application.