Skip to main content
Version: v11.9.4

Export Data from Data Table

9.4 release

Scenario: To export data from a Data Table to excel or CSV format. We will be using the Export option of Data Table to export data from a Database CRUD Variable.

Features specific to rel 9.4

  • Earlier the entire contents of the underlying database table were being exported, post rel 9.4, only the contents displayed in the Data Table will be exported.
  • Also, for each column selected for display, columns can be customized either by
    • column selection can be done from the Advanced Settings, column show/hide checkbox,
    • configuring the Export Options using Value Expressions from the Advanced Settings of the Data Table (NOTE: Value Expression has to be set for custom fields), or
    • writing JavaScript code for the on Before Export callback event for the Data Table.
  • These features are available ONLY for Data Table bound to a Database CRUD variable, Live Filter result, or Query API Variable.

Prerequisites

  1. A WaveMaker Web Application, with a database imported (we are using the sample HR Database).
  2. A page with Data Table bound to a Database CRUD variable, here we are using the Employee table from the sample hrdb.

Steps

  1. Open the Advanced Settings of the Data Table.
  2. From the Data Table tab, scroll down to locate Export Format option and select required format.
  3. Export Data Size property can be used to specify the number of records to be exported.  By default, the value is set to 100, the maximum export size. To export more than 100 records, the max size in the profile needs to be changed from the Project Configurations menu of Project Workspace.
  4. Navigate to Columns tab and note that for each column Export Options tab is visible. Use this to customize the data to be exported. NOTE: If you have any custom columns, value expression has to be given here, else the export will fail.
  5. Save and close the Advanced Settings.
  6. You can further customize the data being exported using the on Before Export callback event of the Data Table.
  7. You can use the following script:
Page.EmployeeTable1Beforeexport = function($data) {

// Change Export Type
$data.exportType = 'CSV';

//Changing the export size
$data.size = 5;

//Apply Sorting on fields
$data.orderBy = "empId desc";

//updating the header
$data.columns.firstname.header = ‘Fullname’;

//updating first name expression
$data.columns.firstname.expression = firstname + ' ' +lastname;

//adding new column
$data.columns.username = {
header: ‘Username’,
expression: firstname + '.' + lastname
}

//Deleting the existing column during Export
delete $data.columns.firstname;
};

Data Table Use Cases