Vue UI Components Documentation
This tutorial shows the two ways to give jqxGrid its rows in a Vue 3 app: let the grid's data adapter load a URL, or load the data yourself, keep it in a ref, and hand it to the grid. You will also add and remove rows by changing that ref.
It is the first of a series of jqxGrid tutorials for Vue. Each one is a complete src/App.vue, written with <script setup lang="ts">, that you can paste into a project and run.

You need a Vite, Vue 3.5 and TypeScript app with jqwidgets-scripts, set up as in Add a Grid to a Vue 3 app: the theme imported in src/main.ts, the components declared in src/jqwidgets-vue3.d.ts, and the two settings that versions before jqwidgets-scripts 27.1.0 need in vite.config.ts (a small plugin for npm run dev, and errorRecovery for npm run build).
The examples use this sample file. Save it as public/products.json; Vite serves the public folder at the site root.
[
{
"id": 1,
"name": "Chai",
"category": "Beverages",
"price": 18,
"inStock": true
},
{
"id": 2,
"name": "Chang",
"category": "Condiments",
"price": 19,
"inStock": true
},
{
"id": 3,
"name": "Aniseed Syrup",
"category": "Confections",
"price": 10,
"inStock": false
},
{
"id": 4,
"name": "Ikura",
"category": "Dairy",
"price": 31,
"inStock": true
},
{
"id": 5,
"name": "Konbu",
"category": "Seafood",
"price": 6,
"inStock": true
},
{
"id": 6,
"name": "Tofu",
"category": "Beverages",
"price": 23.25,
"inStock": true
},
{
"id": 7,
"name": "Pavlova",
"category": "Condiments",
"price": 17.45,
"inStock": false
},
{
"id": 8,
"name": "Mascarpone",
"category": "Confections",
"price": 32,
"inStock": true
}
]
A jqx.dataAdapter describes where the rows come from and the type of each field. Given a url, it loads the rows itself when the grid needs them. The Grid component loads the jQWidgets core, which defines jqx as a global, so the script only declares it. Data, columns and adapter that never change are plain constants of the script, not refs: Vue need not track them, and the grid gets the same objects on every render.
<script setup lang="ts">
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
// Defined globally by the jQWidgets core, which the Grid component imports.
declare const jqx: any;
// The adapter loads the URL itself. A plain constant, not a ref: Vue need not track it.
const source = new jqx.dataAdapter(
{
url: '/products.json',
datatype: 'json',
id: 'id',
datafields: [
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'inStock', type: 'bool' }
]
},
{
loadError: (_xhr: XMLHttpRequest, status: string, error: string) => {
console.error('Loading the products failed:', status, error);
}
}
);
const columns = [
{ text: 'Product', datafield: 'name', width: 220 },
{ text: 'Category', datafield: 'category', width: 160 },
{ text: 'Price', datafield: 'price', cellsformat: 'c2', cellsalign: 'right', align: 'right', width: 110 },
{ text: 'In stock', datafield: 'inStock', columntype: 'checkbox', width: 90 }
];
</script>
<template>
<JqxGrid width="100%" :autoheight="true" theme="material-purple" :source="source" :columns="columns" />
</template>
The datafields types matter: a number field sorts and formats as a number (cellsformat: 'c2' writes it as currency), and a bool field fills the checkbox column. id: 'id' names the field that identifies a row, which methods such as updaterow and getrowdatabyid use.
When the app needs the rows too (to count them, show them elsewhere, or change them), load them with fetch and keep them in a ref. A shallowRef suits a list that is replaced rather than changed in place: Vue tracks the array, and does not wrap every row in a reactive proxy before the grid reads it.
const grid = ref<GridMethods | null>(null);
// The rows. A shallowRef: the array is replaced, never changed in place, so Vue tracks the
// array itself and does not wrap every row in a proxy.
const products = shallowRef<Product[]>([]);
const error = ref<string | null>(null);
// Load the rows once. The AbortController stops the request if the component is unmounted.
const controller = new AbortController();
onMounted(() => {
fetch('/products.json', { signal: controller.signal })
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.json() as Promise<Product[]>;
})
.then((rows) => {
products.value = rows;
})
.catch((e: Error) => {
if (e.name !== 'AbortError') {
error.value = e.message;
}
});
});
onUnmounted(() => controller.abort());
The request starts in onMounted, and the AbortController cancels it if the component is unmounted before it answers. A failed request ends in the catch, and the template shows the message.
The grid keeps one data adapter for its whole life. The adapter keeps the settings object it was made from, so when the rows change, a watcher puts them in its localdata and calls the grid's updatebounddata, which binds the grid to them:
// One data adapter for the grid's life. It keeps this settings object: when the rows change,
// they go into its localdata, and updatebounddata binds the grid to them. 'sort' sorts them as
// the user sorted the grid (without it, 27.1.0 drops the sort, and earlier versions show them
// unsorted under the sort arrow).
const settings = { localdata: products.value, datatype: 'array', id: 'id', datafields };
const source = new jqx.dataAdapter(settings);
watch(products, (rows) => {
settings.localdata = rows;
grid.value?.updatebounddata('sort');
});
Why not a computed that makes a new adapter for :source, as one might in other frameworks? That works in jqwidgets-scripts 27.1.0, but not before it. Earlier versions apply all the Grid component's props to the grid again whenever it re-renders, and the props a template does not set (with their default values) come after the ones it does. A new source is therefore followed by defaults such as showdefaultloadelement and commandcolumn, and the grid stays on Loading...: the new rows are bound, but not drawn. Keeping source the same adapter and changing the rows inside it works with every version.
'sort' tells the grid to sort the new rows the way the user sorted it. Without it, 27.1.0 drops the user's sort and shows the rows in their own order; earlier versions show them in their own order while the column header still shows the sort arrow.
To add or remove rows, the buttons replace the array; the watcher and the grid follow:
function addProduct() {
const current = products.value;
const id = Math.max(0, ...current.map((p) => p.id)) + 1;
products.value = [...current, { id, name: `New product ${id}`, category: 'Beverages', price: 9.5, inStock: true }];
}
function removeOutOfStock() {
products.value = products.value.filter((p) => p.inStock);
}
Rebinding is the right tool when the data set itself changes. To change a few values in rows the grid already shows, call the grid's own methods instead (setcellvalue, updaterow); Large data sets and live updates shows why that is much faster.
Replace src/App.vue:
<script setup lang="ts">
import { onMounted, onUnmounted, ref, shallowRef, watch } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
// 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;
inStock: boolean;
}
// The grid methods this component calls.
interface GridMethods {
updatebounddata: (type?: string) => void;
}
// Options that never change are plain constants.
const datafields = [
{ name: 'id', type: 'number' },
{ name: 'name', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'price', type: 'number' },
{ name: 'inStock', type: 'bool' }
];
const columns = [
{ text: 'Product', datafield: 'name', width: 220 },
{ text: 'Category', datafield: 'category', width: 160 },
{ text: 'Price', datafield: 'price', cellsformat: 'c2', cellsalign: 'right', align: 'right', width: 110 },
{ text: 'In stock', datafield: 'inStock', columntype: 'checkbox', width: 90 }
];
const grid = ref<GridMethods | null>(null);
// The rows. A shallowRef: the array is replaced, never changed in place, so Vue tracks the
// array itself and does not wrap every row in a proxy.
const products = shallowRef<Product[]>([]);
const error = ref<string | null>(null);
// Load the rows once. The AbortController stops the request if the component is unmounted.
const controller = new AbortController();
onMounted(() => {
fetch('/products.json', { signal: controller.signal })
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.json() as Promise<Product[]>;
})
.then((rows) => {
products.value = rows;
})
.catch((e: Error) => {
if (e.name !== 'AbortError') {
error.value = e.message;
}
});
});
onUnmounted(() => controller.abort());
// One data adapter for the grid's life. It keeps this settings object: when the rows change,
// they go into its localdata, and updatebounddata binds the grid to them. 'sort' sorts them as
// the user sorted the grid (without it, 27.1.0 drops the sort, and earlier versions show them
// unsorted under the sort arrow).
const settings = { localdata: products.value, datatype: 'array', id: 'id', datafields };
const source = new jqx.dataAdapter(settings);
watch(products, (rows) => {
settings.localdata = rows;
grid.value?.updatebounddata('sort');
});
function addProduct() {
const current = products.value;
const id = Math.max(0, ...current.map((p) => p.id)) + 1;
products.value = [...current, { id, name: `New product ${id}`, category: 'Beverages', price: 9.5, inStock: true }];
}
function removeOutOfStock() {
products.value = products.value.filter((p) => p.inStock);
}
</script>
<template>
<main style="padding: 16px">
<h1>Products</h1>
<p v-if="error" role="alert">Could not load the products: {{ error }}</p>
<p style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center">
<button type="button" @click="addProduct">Add a product</button>
<button type="button" @click="removeOutOfStock">Remove products not in stock</button>
<span>{{ products.length }} products</span>
</p>
<!-- source and columns are constants: the grid component never applies them again. -->
<JqxGrid ref="grid" width="100%" :autoheight="true" theme="material-purple" :source="source" :columns="columns" />
</main>
</template>
Run npm run dev and open the address it prints. The grid shows the eight products; the buttons add a row and remove the products that are not in stock, and the count next to them follows.