Vue UI Components Documentation
JqxGrid can be bound to multiple types of data collections including arrays, xml, json, tsv, csv or remote data. To data bind the Grid to a data source you need to set its source property to point to an instance of jqxDataAdapter.
The source object represents a set of key/value pairs.
pager: function (pagenum, pagesize, oldpagenum) {
}
sort: function (column, direction) {
}
filter: function (filters, recordsArray) {
}
addrow: function (rowid, rowdata, position, commit) {
// synchronize with the server - send insert command
// call commit with parameter true if the synchronization with the server is successful
//and with parameter false if the synchronization failed.
commit(true);
}
deleterow: function (rowid, commit) {
// synchronize with the server - send delete command
// call commit with parameter true if the synchronization with the server is successful
//and with parameter false if the synchronization failed.
commit(true);
}
updaterow: function (rowid, newdata, commit) {
// synchronize with the server - send update command
// call commit with parameter true if the synchronization with the server is successful
// and with parameter false if the synchronization failed.
commit(true);
}
let source = {
datatype: "jsonp",
datafields: [
{ name: 'countryName' },
{ name: 'name' },
{ name: 'population', type: 'float' },
{ name: 'continentCode' }
],
url: "http://ws.geonames.org/searchJSON",
processdata: function (data) {
data.featureClass = "P";
data.style = "full";
data.maxRows = 50;
}
};let source = {
datatype: "jsonp",
datafields: [
{ name: 'countryName' },
{ name: 'name' },
{ name: 'population', type: 'float' },
{ name: 'continentCode' }
],
url: "http://ws.geonames.org/searchJSON",
data: {
featureClass: "P",
style: "full",
maxRows: 50
},
formatdata: function (data) {
return "my data";
}
};The example code below illustrates how to create jqxDataAdapter from a source object:
dataAdapter: new jqx.dataAdapter(this.source, {
loadComplete: function (data) {
// data is loaded.
},
loadError: function (xhr, status, error) {
// data is not loaded.
}
})If you bind the Grid to remote data source using asynchronous requests( that is by default when you specify url in the source object and you didn't set the async field to false), then make sure that you call any method or set a property once the data is loaded. To ensure that you call your code when the Grid is loaded with data, use the Grid's ready callback function or bind to the 'bindingcomplete' event before the Grid's initialization and call your code inside the event handler.
The data member is array. The datatype member is set to "array".
<template>
<JqxGrid :theme="'material'" :width="width" :source="dataAdapter" :columns="columns"> </JqxGrid>
</template>
<script setup>
import { ref } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
let source = {
localdata: generatedata(50),
datatype: 'array',
datafields: [
{ name: 'firstname', type: 'string' },
{ name: 'lastname', type: 'string' },
{ name: 'productname', type: 'string' },
{ name: 'quantity', type: 'number' },
{ name: 'price', type: 'number' },
{ name: 'total', type: 'number' }
]
};
const width = ref('99%');
const dataAdapter = ref(new jqx.dataAdapter(source));
const columns = ref([
{ text: 'Name', datafield: 'firstname', width: 120 },
{ text: 'Last Name', datafield: 'lastname', width: 120 },
{ text: 'Product', datafield: 'productname', width: 180 },
{ text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' },
{ text: 'Unit Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
{ text: 'Total', datafield: 'total', cellsalign: 'right', cellsformat: 'c2' }
]);
</script>In the source initialization, you need to set the following:
<template>
<JqxGrid :theme="'material'" :width="width" :source="dataAdapter" :columns="columns"> </JqxGrid>
</template>
<script setup>
import { ref } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
let source = {
datatype: 'xml',
datafields: [
{ name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName', type: 'string' },
{ name: 'ContactName', map: 'm\\:properties>d\\:ContactName', type: 'string' },
{ name: 'ContactTitle', map: 'm\\:properties>d\\:ContactTitle', type: 'string' },
{ name: 'City', map: 'm\\:properties>d\\:City', type: 'string' },
{ name: 'PostalCode', map: 'm\\:properties>d\\:PostalCode', type: 'string' },
{ name: 'Country', map: 'm\\:properties>d\\:Country', type: 'string' }
],
root: 'entry',
record: 'content',
id: 'm\\:properties>d\\:CustomerID',
url: '/sampledata/customers.xml'
};
const width = ref('99%');
const dataAdapter = ref(new jqx.dataAdapter(source));
const columns = ref([
{ text: 'Company Name', datafield: 'CompanyName', width: 250 },
{ text: 'Contact Name', datafield: 'ContactName', width: 150 },
{ text: 'Contact Title', datafield: 'ContactTitle', width: 180 },
{ text: 'City', datafield: 'City', width: 120 },
{ text: 'Postal Code', datafield: 'PostalCode', width: 90 },
{ text: 'Country', datafield: 'Country', width: 100 }
]);
</script>When you bind the Grid to JSON data, you need to set the source object's datatype to 'json'.
If you want to bind the Grid to JSONP data, then you need to set the source object's datatype to 'jsonp'.
<template>
<JqxGrid :theme="'material'" :width="width" :source="dataAdapter" :columns="columns"> </JqxGrid>
</template>
<script setup>
import { ref } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
let source = {
datatype: 'json',
datafields: [
{ name: 'name', type: 'string' },
{ name: 'type', type: 'string' },
{ name: 'calories', type: 'int' },
{ name: 'totalfat', type: 'string' },
{ name: 'protein', type: 'string' }
],
id: 'id',
url: '/sampledata/beverages.txt'
};
const width = ref('99%');
const dataAdapter = ref(new jqx.dataAdapter(source));
const columns = ref([
{ text: 'Name', datafield: 'name', width: 250 },
{ text: 'Beverage Type', datafield: 'type', width: 250 },
{ text: 'Calories', datafield: 'calories', width: 180 },
{ text: 'Total Fat', datafield: 'totalfat', width: 120 },
{ text: 'Protein', datafield: 'protein', minwidth: 120 }
]);
</script>When you bind the Grid to TSV data, you need to set the source object's datatype to 'tab'.
<template>
<JqxGrid :theme="'material'" :width="width" :source="dataAdapter" :columns="columns"> </JqxGrid>
</template>
<script setup>
import { ref } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
let source = {
datatype: 'tab',
datafields: [
{ name: 'Year', type: 'int' },
{ name: 'HPI', type: 'float' },
{ name: 'BuildCost', type: 'float' },
{ name: 'Population', type: 'float' },
{ name: 'Rate', type: 'float' }
],
url: '/sampledata/homeprices.txt'
};
const width = ref('99%');
const dataAdapter = ref(new jqx.dataAdapter(source));
const columns = ref([
{ text: 'Year', datafield: 'Year' },
{ text: 'HPI', datafield: 'HPI', cellsformat: 'f2' },
{ text: 'Build Cost', datafield: 'BuildCost', cellsformat: 'f2' },
{ text: 'Population', datafield: 'Population', cellsformat: 'f2' },
{ text: 'Rate', datafield: 'Rate', cellsformat: 'f5', minwidth: 100 }
]);
</script>When you bind the Grid to CSV data, you need to set the source object's datatype to 'csv'.
<template>
<JqxGrid :theme="'material'" :width="width" :source="dataAdapter" :columns="columns"> </JqxGrid>
</template>
<script setup>
import { ref } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
let source = {
datatype: 'csv',
datafields: [
{ name: 'Date', type: 'date' },
{ name: 'S&P 500', type: 'float' },
{ name: 'NASDAQ', type: 'float' }
],
url: '/sampledata/nasdaq_vs_sp500.txt'
};
const width = ref('99%');
const dataAdapter = ref(new jqx.dataAdapter(source));
const columns = ref([
{ text: 'Date', datafield: 'Date', cellsformat: 'D', width: 250 },
{ text: 'S&P 500', datafield: 'S&P 500', width: 300, cellsformat: 'f' },
{ text: 'NASDAQ', datafield: 'NASDAQ', cellsformat: 'f' }
]);
</script>To refresh the Grid, you need to simply set its 'source' property again.
<template>
<div>
<JqxGrid
ref="myGrid"
:theme="'material'"
:width="width"
:source="dataAdapter"
:columns="columns"
>
</JqxGrid>
<div style="height: 20px; margin-top: 15px">
<JqxButton :theme="'material'" :width="50" @click="refreshBtnOnClick()"
>Refresh Data</JqxButton
>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
import JqxButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxbuttons.vue';
const myGrid = ref(null);
let source = {
localdata: generatedata(50),
datafields: [
{ name: 'firstname', type: 'string' },
{ name: 'lastname', type: 'string' },
{ name: 'productname', type: 'string' },
{ name: 'quantity', type: 'number' },
{ name: 'price', type: 'number' },
{ name: 'total', type: 'number' }
],
datatype: 'array'
};
const getWidth = ref('99%');
const dataAdapter = ref(new jqx.dataAdapter(source));
const columns = ref([
{ text: 'First Name', dataField: 'firstname', width: 130 },
{ text: 'Last Name', dataField: 'lastname', width: 130 },
{ text: 'Product', dataField: 'productname', width: 180 },
{ text: 'Quantity', dataField: 'quantity', width: 80, cellsalign: 'right' },
{ text: 'Unit Price', dataField: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
{ text: 'Total', dataField: 'total', cellsalign: 'right', minwidth: 100, cellsformat: 'c2' }
]);
function refreshBtnOnClick() {
this.source.localdata = generatedata(50);
// passing `cells` to the `updatebounddata` method will refresh only the cells values when the new rows count is equal to the previous rows count.
myGrid.value.updatebounddata('cells');
}
</script>