- Loading indicator
- Refresh the datasource using property
- Dynamically change the datasource or columns or both
- Prevent to convert local time zone format for date column
- See also
Contact Support
Data binding in Vue Grid component
7 May 202524 minutes to read
Data binding is a fundamental technique that empowers the Grid component to integrate data into its interface, enabling the creation of dynamic and interactive grid views. This feature is particularly valuable when working with large datasets or when data needs to be fetched remotely.
The Syncfusion® Grid utilizes the DataManager, which supports both local binding with JavaScript object arrays and remote binding with RESTful JSON data services. The key property, dataSource, can be assigned to a DataManager instance or a collection of JavaScript object arrays.
It supports two kinds of data binding methods:
- Local data
- Remote data
To learn about how to bind local, remote or observables data to Vue Grid, you can check on this video:
Loading indicator
The Syncfusion® Vue Grid offers a loading animation feature, which makes it easy to identify when data is being loaded or refreshed. This feature provides a clear understanding of the grid’s current state and actions, such as sorting, filtering, grouping, and more.
To achieve this, you can utilize the loadingIndicator.indicatorType property of the grid, which supports two types of indicators:
- Spinner (default indicator)
- Shimmer
The following example demonstrates how to set the loadingIndicator.indicatorType
property based on changing the dropdown value using the change event of the DropDownList
component. The refreshColumns method is used to apply the changes and display the updated loading indicator type.
W
<template>
<div id="app">
<div style="display: inline-block">
<label style="padding: 10px 10px 26px 0"> Change the loading indicator type: </label>
<ejs-dropdownlist ref="dropdown" index="0" width="120" :dataSource="drobDownData" :fields='fields' :change="valueChange">
</ejs-dropdownlist>
</div>
<ejs-grid ref="grid" style="padding: 10px 10px" :dataSource='dataGrid' :allowPaging='true'
:allowSorting='true' :allowFiltering='true' :pageSettings='pageSettings' :loadingIndicator='loadingIndicator'>
<e-columns>
<e-column field='EmployeeID' headerText='Employee ID' width='130' textAlign='Right'></e-column>
<e-column field='Employees' headerText='Employee Name' width='145'></e-column>
<e-column field='Designation' headerText='Designation' width='130'></e-column>
<e-column field='CurrentSalary' headerText='Current Salary' width='140' format="C2" textAlign='Right'></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { provide,ref} from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns,Page, Toolbar, Edit , Filter,Sort } from "@syncfusion/ej2-vue-grids";
import { DropDownListComponent as EjsDropdownlist } from "@syncfusion/ej2-vue-dropdowns";
import { DataManager, UrlAdaptor } from '@syncfusion/ej2-data';
const dataGrid = new DataManager({ url: 'https://services.syncfusion.com/vue/production/api/urldatasource', adaptor: new UrlAdaptor });
const loadingIndicator ={ indicatorType: 'Spinner' };
const pageSettings ={ pageCount: 3 };
const grid=ref(null);
const dropdown=ref(null);
const drobDownData= [
{ id: 'Spinner', value: 'Spinner' },
{ id: 'Shimmer', value: 'Shimmer' }
];
const fields= { text: 'value', value: 'id' };
const valueChange=function(args) {
grid.value.ej2Instances.loadingIndicator.indicatorType = args.value;
grid.value.refreshColumns();
}
provide('grid', [Page, Toolbar, Edit , Filter,Sort]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<div style="display: inline-block">
<label style="padding: 10px 10px 26px 0"> Change the loading indicator type: </label>
<ejs-dropdownlist ref="dropdown" index="0" width="120" :dataSource="drobDownData" :fields='fields' :change="valueChange">
</ejs-dropdownlist>
</div>
<ejs-grid ref="grid" style="padding: 10px 10px" :dataSource='dataGrid' :allowPaging='true'
:allowSorting='true' :allowFiltering='true' :pageSettings='pageSettings' :loadingIndicator='loadingIndicator'>
<e-columns>
<e-column field='EmployeeID' headerText='Employee ID' width='130' textAlign='Right'></e-column>
<e-column field='Employees' headerText='Employee Name' width='145'></e-column>
<e-column field='Designation' headerText='Designation' width='130'></e-column>
<e-column field='CurrentSalary' headerText='Current Salary' width='140' format="C2" textAlign='Right'></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective, Page, Toolbar, Edit , Filter,Sort} from "@syncfusion/ej2-vue-grids";
import { DataManager, UrlAdaptor } from '@syncfusion/ej2-data';
import { DropDownListComponent } from "@syncfusion/ej2-vue-dropdowns";
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
'ejs-dropdownlist' : DropDownListComponent,
},
data() {
return {
dataGrid : new DataManager({ url: 'https://services.syncfusion.com/vue/production/api/urldatasource', adaptor: new UrlAdaptor }),
loadingIndicator :{ indicatorType: 'Spinner' },
pageSettings : { pageCount: 3 },
drobDownData: [
{ id: 'Spinner', value: 'Spinner' },
{ id: 'Shimmer', value: 'Shimmer' }
],
fields: { text: 'value', value: 'id' }
};
},
methods: {
valueChange(args) {
this.$refs.grid.ej2Instances.loadingIndicator.indicatorType = args.value;
this.$refs.grid.ej2Instances.refreshColumns();
}
},
provide: {
grid: [Page, Edit, Toolbar, Filter,Sort]
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
Refresh the datasource using property
Refreshing the data source in a Syncfusion® Grid involves updating the data that the grid displays dynamically. This operation is Essential® when you need to reflect changes in the underlying data without reloading the entire page or component.
To achieve this, you can make use of the datasource property in conjunction with the setProperties method. This ensures that the grid reflects the changes in the data source without requiring a complete page or component reload.
For example, if you add or delete data source records, follow these steps:
Step 1: Add/delete the datasource record by using the following code.
this.$refs.grid.ej2Instances.dataSource.unshift(data); // Add a new record.
this.$refs.grid.ej2Instances.dataSource.splice(selectedRow, 1); // Delete a record.
Step 2: Refresh the datasource after changes by invoking the setProperties
method.
this.$refs.grid.ej2Instances.setProperties({ dataSource: this.$refs.grid.ej2Instances..dataSource});
The following example demonstrates adding a new record to the data source through an external button:
<template>
<div id="app">
<div style="padding: 5px 0px 20px 0px ">
<ejs-button id="sample" v-on:click='changeDatasource'> Refresh Datasource </ejs-button>
</div>
<ejs-grid ref="grid" :dataSource='dataGrid' :height='280' >
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=90></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
<e-column field='Freight' headerText='Freight' textAlign='Right' format='C2' width=90></e-column>
<e-column field='ShipCity' headerText='Ship City' width=120 ></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { ref} from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns} from "@syncfusion/ej2-vue-grids";
import { ButtonComponent as EjsButton } from "@syncfusion/ej2-vue-buttons";
import { data } from './datasource.js';
const dataGrid=data;
const grid=ref(null);
let newRecords =ref({});
const changeDatasource=function(){
for (let i = 0; i < 5; i++) {
newRecords.value = {
OrderID: generateOrderId(),
CustomerID: generateCustomerId(),
ShipCity: generateShipCity(),
Freight: generateFreight(),
ShipName: generateShipName()
};
grid.value.ej2Instances.dataSource.unshift(newRecords.value);
grid.value.setProperties({ dataSource: grid.value.ej2Instances.dataSource});
}
};
// Generate a random OrderID
const generateOrderId=function() {
return Math.floor(10000 + Math.random() * 90000);
};
// Generate a random CustomerID
const generateCustomerId=function() {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
for (let i = 0; i < 5; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
};
// Generate a random ShipCity
const generateShipCity=function(){
const cities = ['London', 'Paris', 'New York', 'Tokyo', 'Berlin'];
return cities[Math.floor(Math.random() * cities.length)];
};
// Generate a random Freight value
const generateFreight=function(){
return Math.random() * 100;
};
// Generate a random ShipName
const generateShipName=function(){
const names = ['Que Delícia', 'Bueno Foods', 'Island Trading', 'Laughing Bacchus Winecellars'];
return names[Math.floor(Math.random() * names.length)];
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<div style="padding: 5px 0px 20px 0px ">
<ejs-button id="sample" v-on:click='changeDatasource'> Refresh Datasource </ejs-button>
</div>
<ejs-grid ref="grid" :dataSource='dataGrid' :height='280' >
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=90></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=120></e-column>
<e-column field='Freight' headerText='Freight' textAlign='Right' format='C2' width=90></e-column>
<e-column field='ShipCity' headerText='Ship City' width=120 ></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective} from "@syncfusion/ej2-vue-grids";
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";
import { data } from './datasource.js';
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
"ejs-button": ButtonComponent
},
data() {
return {
dataGrid : data
};
},
methods: {
changeDatasource(){
for (let i = 0; i < 5; i++) {
this.newRecords = {
OrderID: this.generateOrderId(),
CustomerID: this.generateCustomerId(),
ShipCity: this.generateShipCity(),
Freight: this.generateFreight(),
ShipName: this.generateShipName()
};
this.$refs.grid.dataSource.unshift(this. newRecords);
this.$refs.grid.setProperties({ dataSource: this.$refs.grid.dataSource});
}
},
// Generate a random OrderID
generateOrderId() {
return Math.floor(10000 + Math.random() * 90000);
},
// Generate a random CustomerID
generateCustomerId() {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
for (let i = 0; i < 5; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
},
// Generate a random ShipCity
generateShipCity(){
const cities = ['London', 'Paris', 'New York', 'Tokyo', 'Berlin'];
return cities[Math.floor(Math.random() * cities.length)];
},
// Generate a random Freight value
generateFreight(){
return Math.random() * 100;
},
// Generate a random ShipName
generateShipName(){
const names = ['Que Delícia', 'Bueno Foods', 'Island Trading', 'Laughing Bacchus Winecellars'];
return names[Math.floor(Math.random() * names.length)];
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
Dynamically change the datasource or columns or both
The Grid component in Syncfusion® allows dynamic modification of the data source, columns, or both . This feature is particularly valuable when you need to refresh the grid’s content and structure without requiring a complete page reload.
To achieve dynamic changes, you can utilize the changeDataSource method. This method enables you to update the data source, columns, or both, based on your application’s requirements. However, it is important to note that during the changing process for the data source and columns, the grid’s existing actions such as sorting, filtering, grouping, aggregation, and searching will be reset.The changeDataSource
method has two optional arguments: the first argument represents the data source, and the second argument represents the columns. The various uses of the changeDataSource
method are explained in the following topic.
1. Change both data source and columns:
To modify both the existing columns and the data source, you need to pass the both arguments to the changeDataSource
method. The following example demonstrates how to change both the data source and columns.
You can assign a JavaScript object array to the dataSource property to bind local data to the grid. The code below provides an example of how to create a data source for the grid.
export let data= [
{
OrderID: 10248, CustomerID: 'VINET', Freight: 32.38,
ShipCity: 'Reims'
},
{
OrderID: 10249, CustomerID: 'TOMSP', Freight: 11.61,
ShipCity: 'Münster'
},
{
OrderID: 10250, CustomerID: 'HANAR', Freight: 61.34,
ShipCity: 'Rio de Janeiro'
}];
The following code demonstrates how to create the columns for the grid, which are based on the provided grid data source.
newColumn= [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 125 },
{ field: 'CustomerID', headerText: 'Customer ID', width: 125 },
];
The following code demonstrates updating the data source and columns defined above using the changeDataSource
method.
this.$refs.grid.ej2Instances.changeDataSource(data, newColumn);
2. Modify only the existing columns:
To modify the existing columns in a grid, you can either add or remove columns or change the entire set of columns using the changeDataSource method. To use this method, you should set the first parameter to null and provide the new columns as the second parameter. However, please note that if a column field is not specified in the data source, its corresponding column values will be empty. The following example illustrates how to modify existing columns.
The following code demonstrates how to add new columns with existing grid columns (‘newColumn’) by using changeDataSource
method.
newColumn1= [
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 125 },
{ field: 'ShipCity', headerText: 'ShipCity', width: 125 },
];
let column: any = this.newColumn.push(...this.newColumn1);
this.$refs.grid.ej2Instances..changeDataSource(null, column);
3. Modify only the data source:
You can change the entire data source in the grid using the changeDataSource
method. To use this method, you should provide the data source as the first argument, and the second argument which is optional can be used to specify new columns for the grid. If you are not specifying the columns, the grid will generate the columns automatically based on the data source. The following example demonstrates how to modify the data source.
You can assign a JavaScript object array to the dataSource
property to bind local data to the grid. The code below provides an example of how to create a new data source for the grid.
export let employeeData = [
{
FirstName: 'Nancy', City: 'Seattle', Region: 'WA',
Country: 'USA'
},
{
FirstName: 'Andrew', City: 'London', Region: null,
Country: 'UK',
},
{
FirstName: 'Janet', City: 'Kirkland', Region: 'WA',
Country: 'USA'
}];
The following code demonstrates, how to use the changeDataSource
method to bind the new employeeData to the grid.
this.$refs.gridInstance.ej2Instances.changeDataSource(employeeData);
<template>
<div id="app">
<div style="padding:0px 0px 20px 0px">
<ejs-button @click="next">Change datasource and column</ejs-button >
</div>
<ejs-grid ref="grid" :dataSource="dataGrid" allowPaging="true" :pageSettings="pageSettings" >
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' textAlign='Right' width=120></e-column>
<e-column field='Freight' headerText='Freight' textAlign='Right' width=120></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { provide,ref } from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns, Page } from "@syncfusion/ej2-vue-grids";
import { ButtonComponent as EjsButton } from "@syncfusion/ej2-vue-buttons";
import { data } from './datasource.js';
const dataGrid = data;
const pageSettings={ pageSize: 5, pageCount: 3 };
const count =ref(0);
const grid=ref(null);
const newColumn = [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 125 },
{ field: 'CustomerName', headerText: 'Customer Name', width: 125 },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right'},
{ field: 'Freight', headerText: 'Freight', width: 120, textAlign: 'Right'},
]
const next=function() {
count.value = count.value + 100;
grid.value.ej2Instances.changeDataSource(data.slice(0, count.value + 100), newColumn);
}
provide('grid', [Page]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<div style="padding:0px 0px 20px 0px">
<ejs-button @click="next">Change datasource and column</ejs-button >
</div>
<ejs-grid ref="grid" :dataSource="dataGrid" allowPaging="true" :pageSettings="pageSettings" >
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' textAlign='Right' width=120></e-column>
<e-column field='Freight' headerText='Freight' textAlign='Right' width=120></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective,Page} from "@syncfusion/ej2-vue-grids";
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";
import { data } from './datasource.js';
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
"ejs-button": ButtonComponent
},
data() {
return {
dataGrid : data,
pageSettings: { pageSize: 5, pageCount: 3 },
count : 0,
newColumn : [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 125 },
{ field: 'CustomerName', headerText: 'Customer Name', width: 125 },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right'},
{ field: 'Freight', headerText: 'Freight', width: 120, textAlign: 'Right'},
]
};
},
methods: {
next() {
this.count = this.count + 100;
this.$refs.grid.ej2Instances.changeDataSource(data.slice(0, this.count + 100), this.newColumn);
}
},
provide: {
grid: [Page]
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
- The Grid state persistence feature does not support the
changeDataSource
method.- In this document, the above sample uses the local data for
changeDataSource
method. For those using a remote data source, refer to the FlexibleData resource.
Prevent to convert local time zone format for date column
By default, Syncfusion® Vue Grid automatically converts date values to the local time zone of the client system. However, in some scenarios, you may need to display the original date as received from the server without any timezone conversion.
To prevent timezone conversion for a date column, use the serverTimezoneOffset
property from DataUtil
. Setting this property to 0 ensures that dates remain in the original format received from the server without conversion to the local timezone.
The following example demonstrates how to prevent local time zone conversion for date columns in Grid by using the DataUtil.serverTimezoneOffset
property:
<template>
<div id="app">
<div style="display: flex; align-items: center; margin-bottom: 10px">
<label style="margin-right: 10px">Select Timezone:</label>
<ejs-dropdownlist
id="timezone"
width="150px"
:dataSource="timeZones"
:fields="field"
v-model="selectedTimezone"
:change="onTimezoneChange"
></ejs-dropdownlist>
</div>
<div style="margin-bottom: 10px">
<ejs-checkbox
label="Prevent Timezone Conversion"
ref="timezoneCheckboxRef"
:change="onCheckboxChange"
></ejs-checkbox>
</div>
<ejs-grid ref="grid" :dataSource="data" :height="315" :load="load">
<e-columns>
<e-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-column>
<e-column field="CustomerID" headerText="Customer ID" width="140"></e-column>
<e-column field="Freight" headerText="Freight" textAlign="Right" format="C" width="120"></e-column>
<e-column field="OrderDate" headerText="Order Date" textAlign="Right" width="140"></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script setup>
import { ref } from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-grids";
import { CheckBoxComponent as EjsCheckbox } from "@syncfusion/ej2-vue-buttons";
import { DropDownListComponent as EjsDropdownlist } from "@syncfusion/ej2-vue-dropdowns";
import { DataManager, WebApiAdaptor, DataUtil } from "@syncfusion/ej2-data";
const SERVICE_URI = "https://services.syncfusion.com/vue/production/";
const data = new DataManager({
url: SERVICE_URI + 'api/Orders',
adaptor: new WebApiAdaptor(),
crossDomain: true
})
const selectedTimezone =ref(-12);
const grid=ref(null);
const timezoneCheckboxRef=ref(null);
const field ={ text: "text", value: "value" };
const timeZones= [
{ value: -12, text: "-12:00 UTC" },
{ value: -11, text: "-11:00 UTC" },
{ value: -10, text: "-10:00 UTC" },
{ value: -9, text: "-09:00 UTC" },
{ value: -8, text: "-08:00 UTC" },
{ value: -7, text: "-07:00 UTC" },
{ value: -6, text: "-06:00 UTC" },
{ value: -5, text: "-05:00 UTC" },
{ value: -4, text: "-04:00 UTC" },
{ value: -3, text: "-03:00 UTC" },
{ value: -2, text: "-02:00 UTC" },
{ value: -1, text: "-01:00 UTC" },
{ value: 0, text: "+00:00 UTC" },
{ value: 1, text: "+01:00 UTC" },
{ value: 2, text: "+02:00 UTC" },
{ value: 3, text: "+03:00 UTC" },
{ value: 4, text: "+04:00 UTC" },
{ value: 5, text: "+05:00 UTC" },
{ value: 5.5, text: "+05:30 UTC" },
{ value: 6, text: "+06:00 UTC" },
{ value: 7, text: "+07:00 UTC" },
{ value: 8, text: "+08:00 UTC" },
{ value: 9, text: "+09:00 UTC" },
{ value: 10, text: "+10:00 UTC" },
{ value: 11, text: "+11:00 UTC" },
{ value: 12, text: "+12:00 UTC" },
{ value: 13, text: "+13:00 UTC" },
{ value: 14, text: "+14:00 UTC" },
];
const onTimezoneChange = function(args) {
selectedTimezone.value = Number(args.value);
grid.value.ej2Instances.freezeRefresh();
};
const onCheckboxChange = function(args) {
grid.value.ej2Instances.freezeRefresh();
};
const load = function(args) {
DataUtil.serverTimezoneOffset = timezoneCheckboxRef.value.ej2Instances.checked
? 0
: selectedTimezone.value;
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>
<template>
<div id="app">
<div style="display: flex; align-items: center; margin-bottom: 10px">
<label style="margin-right: 10px">Select Timezone:</label>
<ejs-dropdownlist
id="timezone"
width="150px"
:dataSource="timeZones"
:fields="field"
v-model="selectedTimezone"
:change="onTimezoneChange"
></ejs-dropdownlist>
</div>
<div style="margin-bottom: 10px">
<ejs-checkbox
label="Prevent Timezone Conversion"
ref="timezoneCheckboxRef"
:change="onCheckboxChange"
></ejs-checkbox>
</div>
<ejs-grid ref="grid" :dataSource="data" :height="315" :load="load">
<e-columns>
<e-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-column>
<e-column field="CustomerID" headerText="Customer ID" width="140"></e-column>
<e-column field="Freight" headerText="Freight" textAlign="Right" format="C" width="120"></e-column>
<e-column field="OrderDate" headerText="Order Date" textAlign="Right" width="140"></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective} from "@syncfusion/ej2-vue-grids";
import { CheckBoxComponent } from "@syncfusion/ej2-vue-buttons";
import { DropDownListComponent } from "@syncfusion/ej2-vue-dropdowns";
import { DataManager, WebApiAdaptor, DataUtil } from "@syncfusion/ej2-data";
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
"ejs-checkbox": CheckBoxComponent,
"ejs-dropdownlist":DropDownListComponent
},
data() {
let SERVICE_URI = "https://services.syncfusion.com/vue/production/";
return {
data: new DataManager({
url: SERVICE_URI + 'api/Orders',
adaptor: new WebApiAdaptor()
}),
selectedTimezone: -12,
field: { text: "text", value: "value" },
timeZones: [
{ value: -12, text: "-12:00 UTC" },
{ value: -11, text: "-11:00 UTC" },
{ value: -10, text: "-10:00 UTC" },
{ value: -9, text: "-09:00 UTC" },
{ value: -8, text: "-08:00 UTC" },
{ value: -7, text: "-07:00 UTC" },
{ value: -6, text: "-06:00 UTC" },
{ value: -5, text: "-05:00 UTC" },
{ value: -4, text: "-04:00 UTC" },
{ value: -3, text: "-03:00 UTC" },
{ value: -2, text: "-02:00 UTC" },
{ value: -1, text: "-01:00 UTC" },
{ value: 0, text: "+00:00 UTC" },
{ value: 1, text: "+01:00 UTC" },
{ value: 2, text: "+02:00 UTC" },
{ value: 3, text: "+03:00 UTC" },
{ value: 4, text: "+04:00 UTC" },
{ value: 5, text: "+05:00 UTC" },
{ value: 5.5, text: "+05:30 UTC" },
{ value: 6, text: "+06:00 UTC" },
{ value: 7, text: "+07:00 UTC" },
{ value: 8, text: "+08:00 UTC" },
{ value: 9, text: "+09:00 UTC" },
{ value: 10, text: "+10:00 UTC" },
{ value: 11, text: "+11:00 UTC" },
{ value: 12, text: "+12:00 UTC" },
{ value: 13, text: "+13:00 UTC" },
{ value: 14, text: "+14:00 UTC" },
],
};
},
methods: {
onTimezoneChange(args) {
this.selectedTimezone = Number(args.value);
this.$refs.grid.ej2Instances.freezeRefresh();
},
onCheckboxChange(args) {
this.$refs.grid.ej2Instances.freezeRefresh();
},
load(args) {
DataUtil.serverTimezoneOffset = this.$refs.timezoneCheckboxRef.ej2Instances.checked
? 0
: this.selectedTimezone;
},
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/tailwind.css";
</style>