Vue UI Components Documentation
This tutorial exports the grid's rows to Excel, CSV, PDF and JSON files, and remembers the grid's layout (sort, filters, page, column widths and order) in the browser, so it is back the next time the page opens.

Use a Vite and Vue 3 app set up as in Add a Grid to a Vue 3 app. Excel export needs JSZip:
npm install jszip
exportdata(type, fileName) builds the file in the browser and downloads it. The types include xlsx, csv, tsv, pdf, json, xml and html. The file holds every row as the grid sorts and filters it, not only the current page, with the values formatted as the cells show them. A number column without cellsformat is written with two decimals (79.00), so the In stock column sets cellsformat: 'n0'.
Excel files need two imports that the Grid component does not make itself: the library's exporter, and JSZip, which the exporter looks for as a global. Without the first, the Excel button throws DataExporter is not a constructor; without JSZip, Missing reference to 'jszip.min.js'. The other file types need neither.
// Excel (xlsx) export: the Grid component does not load this part of the library, and it
// builds the file with JSZip, which it looks for as a global.
import 'jqwidgets-scripts/jqwidgets/jqxexport';
import JSZip from 'jszip';
(window as unknown as { JSZip: typeof JSZip }).JSZip = JSZip;
// The rows as the grid shows them now (sorted and filtered), in a file.
function exportAs(type: 'xlsx' | 'csv' | 'pdf' | 'json') {
grid.value?.exportdata(type, 'products');
}
For a printout, window.print() prints the page; exportdata('html', …) gives a file with the grid's rows as an HTML table, if you prefer to print only those.
getstate() returns the grid's layout as an object, and loadstate(state) puts it back. The component saves it to localStorage each time the user sorts, filters, pages, or resizes or moves a column (@sort, @filter, @pagechanged, @pagesizechanged, @columnresized, @columnreordered), and puts it back in onMounted, once the grid exists. It also keeps the layout the grid starts with, which Reset the layout loads again.
The grid also has savestate(), which returns the same object but also writes it to localStorage under its own key, and throws when storage is blocked. getstate() leaves storage to your code.
const STORAGE_KEY = 'products-grid-state';
const grid = ref<GridMethods | null>(null);
const saved = ref<string | null>(null);
// The layout the grid starts with, for "Reset the layout".
let initialState: unknown = null;
// loadstate raises sort, filter and page events while it puts a layout back, before it is
// done. Those must not be saved.
let loading = false;
function load(state: unknown) {
loading = true;
try {
grid.value?.loadstate(state);
} finally {
loading = false;
}
}
// Put back the state of the last visit once the grid exists.
onMounted(() => {
initialState = grid.value?.getstate() ?? null;
let state: unknown = null;
try {
state = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? 'null');
} catch {
// ignore a damaged or unreadable entry
}
if (state) {
load(state);
}
});
// Sorting, filtering, paging, a resized or moved column: the grid's state is saved each time.
function saveState() {
if (loading) {
return;
}
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(grid.value?.getstate()));
saved.value = new Date().toLocaleTimeString();
} catch {
// storage full or blocked (private window): the grid works without it
}
}
function resetLayout() {
if (initialState) {
load(initialState);
}
try {
localStorage.removeItem(STORAGE_KEY);
} catch {
// nothing saved
}
saved.value = null;
}
The loading flag matters. loadstate raises the same sort, filter and pagechanged events while it puts the layout back. Without the flag, every visit saved the layout again before the user did anything, and the page opened with Layout saved at …. initialState and loading are plain variables, not refs: nothing on the page is drawn from them.
Storage can fail (a private window, a full quota, a blocked site), so every access is in a try block: the grid works without it. To keep a user's layout across devices, send the same object to your server instead.
The message next to Reset the layout re-renders the component each time the layout is saved. JqxGrid's props are all constants, so the grid is not re-rendered and keeps the sort or filter that was just saved.
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
// Excel (xlsx) export: the Grid component does not load this part of the library, and it
// builds the file with JSZip, which it looks for as a global.
import 'jqwidgets-scripts/jqwidgets/jqxexport';
import JSZip from 'jszip';
(window as unknown as { JSZip: typeof JSZip }).JSZip = JSZip;
// Defined globally by the jQWidgets core, which the Grid component imports.
declare const jqx: any;
interface Product {
id: number;
name: string;
category: string;
price: number;
stock: number;
}
// The grid methods this component calls.
interface GridMethods {
getstate: () => unknown;
loadstate: (state: unknown) => void;
exportdata: (type: string, fileName: string) => void;
}
const categories = ['Beverages', 'Condiments', 'Confections', 'Dairy', 'Seafood'];
const names = ['Chai', 'Chang', 'Aniseed Syrup', 'Ikura', 'Konbu', 'Tofu', 'Pavlova', 'Teatime Biscuits', 'Mascarpone', 'Gnocchi', 'Inlagd Sill', 'Gravad lax'];
const products: Product[] = Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
category: categories[(i * 3) % categories.length],
price: Math.round((3 + ((i * 37) % 60) + ((i * 13) % 100) / 100) * 100) / 100,
stock: (i * 17) % 120
}));
const source = new jqx.dataAdapter({
localdata: products,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'stock', type: 'number' }
]
});
const columns = [
{ text: 'Product', datafield: 'name', width: 220 },
{ text: 'Category', datafield: 'category', width: 150 },
{ text: 'Price', datafield: 'price', width: 110, cellsformat: 'c2', cellsalign: 'right', align: 'right' },
// n0: exports write whole numbers without decimals (79, not 79.00).
{ text: 'In stock', datafield: 'stock', cellsformat: 'n0', cellsalign: 'right', align: 'right' }
];
const STORAGE_KEY = 'products-grid-state';
const grid = ref<GridMethods | null>(null);
const saved = ref<string | null>(null);
// The layout the grid starts with, for "Reset the layout".
let initialState: unknown = null;
// loadstate raises sort, filter and page events while it puts a layout back, before it is
// done. Those must not be saved.
let loading = false;
function load(state: unknown) {
loading = true;
try {
grid.value?.loadstate(state);
} finally {
loading = false;
}
}
// Put back the state of the last visit once the grid exists.
onMounted(() => {
initialState = grid.value?.getstate() ?? null;
let state: unknown = null;
try {
state = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? 'null');
} catch {
// ignore a damaged or unreadable entry
}
if (state) {
load(state);
}
});
// Sorting, filtering, paging, a resized or moved column: the grid's state is saved each time.
function saveState() {
if (loading) {
return;
}
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(grid.value?.getstate()));
saved.value = new Date().toLocaleTimeString();
} catch {
// storage full or blocked (private window): the grid works without it
}
}
function resetLayout() {
if (initialState) {
load(initialState);
}
try {
localStorage.removeItem(STORAGE_KEY);
} catch {
// nothing saved
}
saved.value = null;
}
// The rows as the grid shows them now (sorted and filtered), in a file.
function exportAs(type: 'xlsx' | 'csv' | 'pdf' | 'json') {
grid.value?.exportdata(type, 'products');
}
function print() {
window.print();
}
</script>
<template>
<main style="padding: 16px">
<h1>Products</h1>
<p style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center">
Export:
<button type="button" @click="exportAs('xlsx')">Excel</button>
<button type="button" @click="exportAs('csv')">CSV</button>
<button type="button" @click="exportAs('pdf')">PDF</button>
<button type="button" @click="exportAs('json')">JSON</button>
<button type="button" @click="print">Print</button>
</p>
<p style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center">
<button type="button" @click="resetLayout">Reset the layout</button>
<span aria-live="polite">{{ saved ? `Layout saved at ${saved}` : 'Sort, filter or resize: the layout is kept for your next visit.' }}</span>
</p>
<!-- Every prop is a constant: the saved message re-renders this component, not the grid. -->
<JqxGrid
ref="grid"
width="100%"
:autoheight="true"
theme="material-purple"
:source="source"
:columns="columns"
:sortable="true"
:filterable="true"
:showfilterrow="true"
:pageable="true"
:columnsresize="true"
:columnsreorder="true"
@sort="saveState"
@filter="saveState"
@pagechanged="saveState"
@pagesizechanged="saveState"
@columnresized="saveState"
@columnreordered="saveState"
/>
</main>
</template>
Sort by price and click Excel: products.xlsx holds all 60 products, the most expensive first. Reload the page: the grid is still sorted by price. Reset the layout puts back the starting sort, filters, page, column widths and order, and forgets the saved layout.