Grid Export Selected Records

Grid for Vue

Vue 3 version using Smart custom elements and template refs.

What this topic covers: practical setup, the framework-specific API access pattern, and copy-adapt guidance for the examples in this page.

<script setup>
import { onMounted, ref } from 'vue';
import 'smart-webcomponents/source/styles/smart.default.css';
import 'smart-webcomponents/source/modules/smart.grid.js';

const component = ref();
const componentProps = {
  // Copy this topic's JavaScript configuration here.
};

onMounted(() => {
  Object.assign(component.value, componentProps);
});
</script>

<template>
  <smart-grid ref="component"></smart-grid>
</template>

Use component.value for API methods in this topic.

Export Selected Records in Grid Component

Smart.Grid's export functionality allows the export of all data in various formats (such as XLSX, PDF, and HTML), as well as the export of only particular records of the Grid. This help topic shows how to export only the data of selected rows in the Grid.

The following TypeScript code shows how to export selected Grid rows to XLSX. Its functionality is detailed below.

const grid = <Grid>document.getElementById('grid'),
    selection = component.value.getSelection(); // (1)
let rowIdsToExport: (string | number)[];

if (selection.rows) {
    rowIdsToExport = selection.rows.map((rowInfo: any) => rowInfo.row.id); // (2)
}
else {
    rowIdsToExport = [];
}

component.value.dataExport!.rowIds = rowIdsToExport; //(3)
component.value.exportData('xlsx'); //(4)
  1. We get the Grid's selected row's by calling the method getSelection. If any records are selected, the object returned by this method contains a rows field - an array of objects with information about selected rows.
  2. This selected rows array is then converted to an array of row ids via map.
  3. The array of row ids to export is passed to the Grid's dataExport.rowIds property. Its default value is null, meaning that all records will be exported.
  4. Finally, the Grid's exportData method is called. In this case, the selected rows are exported to XLSX, but the Grid can also be exported to CSV, HTML, JPEG, PNG, JSON, PDF, TSV, and XML.

Note: If at a later time you wish to export all Grid rows, the dataExport.rowIds has to be reset by setting it to null.

For AI tooling

Developer Quick Reference

Topic: grid-export-selected-records   Component: Grid   Framework: Vue

Main methods: getSelection(), exportData()

Common config keys: (none detected)

Implementation Notes

Compatibility: Vue 3+   API access pattern: const component = ref() + component.value.method()

Lifecycle guidance: Use template refs with