How can I help you?
Querying in Vue DataManager
16 Apr 202624 minutes to read
The Query class in Syncfusion® Vue DataManager is used to build structured queries that interact with a data source. The queries define operations such as filtering, sorting, paging, and grouping, making it easier to retrieve and manipulate data in a consistent way.
By combining DataManager with the Query class, data operations can be executed either locally or against a remote service, depending on the configuration. This approach ensures that data handling remains efficient and flexible across different scenarios.
Key capabilities of Query class:
- Filtering: Retrieve records that match specific conditions.
- Sorting: Arrange records in ascending or descending order.
- Paging: Limit the number of records returned at once.
- Grouping: Organize records into logical categories.
Specifying resource name using from
The Query class allows defining the source from which data should be retrieved. The from method specifies the resource name, such as a table or endpoint, and sets the context for all subsequent query operations. Once the resource is defined, filtering, sorting, paging, and other operations can be applied seamlessly to that target source.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().from('Orders').take(12)).then((e) => {
items.value = e.result;
});
});
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().from('Orders').take(12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Projection using select
The select method in the Query class is used to project specific fields from a data source. Instead of retrieving all columns, select allows choosing only the required fields. This reduces the amount of data returned, minimizes payload size, and improves performance by limiting unnecessary information.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().select(['OrderID', 'CustomerID', 'EmployeeID']).take(12)).then((e) => {
items.value = e.result;
});
})
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().select(['OrderID', 'CustomerID', 'EmployeeID']).take(12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Loading related data with expand
The expand method in the Query class is used to include related records when retrieving data. This technique, known as eager loading, ensures that navigation properties are fetched along with the main dataset. By expanding relationships, hierarchical or associated data can be accessed directly using dot‑separated field notation, making complex data retrieval more efficient.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee Name</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.Employee.FirstName }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query()
.expand('Employee').take(12)).then((e) => {
items.value = e.result;
});
});
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee Name</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.Employee.FirstName }}</td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query()
.expand('Employee').take(12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Sorting
The sortBy method in the Query class arranges records in “ascending” order by default, while sortByDesc applies “descending” order. Alternatively, the descending parameter in sortBy can be used to specify sort direction. These methods enable precise control over data ordering based on selected fields.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().sortBy('CustomerID', 'descending').take(12)).then((e) => {
items.value = e.result;
});
});
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().sortBy('CustomerID', 'descending').take(12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Multi sorting can be performed by simply chaining the multiple
sortBymethods.
Filtering
The where method in the Query class defines filter conditions to retrieve records that match specific criteria. Multiple filters can be combined using chainable syntax, enabling precise and efficient queries for complex scenarios.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().where('EmployeeID', 'equal', 3).take(12)).then((e) => {
items.value = e.result;
});
})
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().where('EmployeeID', 'equal', 3).take(12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Filter Operators
Filter operators are generally used to specify the filter type. The various filter operators supported by DataManager is listed below.
- greaterthan
- greaterthanorequal
- lessthan
- lessthanorequal
- equal
- notequal
- startswith
- endswith
- contains
These filter operators are used for creating filter query using
wheremethod andPredicateclass.
Complex filter criteria using Predicate
The Predicate class enables advanced filtering by combining multiple conditions using logical operators like AND and OR. It offers a structured approach to building complex queries beyond simple chaining, supporting powerful and flexible data filtering.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor, Predicate } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let predicate = new Predicate('EmployeeID', 'equal', 3);
predicate = predicate.and('ShipCountry', 'equal', 'Germany');
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().where(predicate).take(12)).then((e) => {
items.value = e.result;
});
})
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor, Predicate } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let predicate = new Predicate('EmployeeID', 'equal', 3);
predicate = predicate.and('ShipCountry', 'equal', 'Germany');
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().where(predicate).take(12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Searching
The search method in the Query class performs a global search by applying a keyword across all fields in the dataset. It retrieves records with matches in any column, enabling broad and efficient data exploration beyond field‑specific filtering.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { data } from './datasource.js';
import { DataManager, Query } from '@syncfusion/ej2-data';
const items = new DataManager(data).executeLocal(new Query().search('VI', ['CustomerID']));
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script>
import { data } from './datasource.js';
import { DataManager, Query } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: new DataManager(data).executeLocal(new Query().search('VI', ['CustomerID']))
};
},
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>To perform a search on specific fields, provide an array of field names as the second argument to the search method.
Grouping
The group method in the Query class organizes records into logical categories based on specified fields. This enables hierarchical structuring of data, making it easier to aggregate and present related records together. When combined with the DataManager, grouping supports efficient data analysis and visualization.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tbody v-for="(group, key) in items" :key="key">
<tr>
<td>{{ group.field }} - {{ group.key }}</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr v-for="(item, index) in group.items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().group('CustomerID').take(12)).then((e) => {
items.value = e.result;
});
});
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tbody v-for="(group, key) in items" :key="key">
<tr>
<td>{{ group.field }} - {{ group.key }}</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr v-for="(item, index) in group.items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().group('CustomerID').take(12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Multiple grouping can be done by simply chaining the
groupmethod.
Paging
The page method in the Query class retrieves records based on a specified page index and page size. This approach divides large datasets into smaller segments, improving performance and reducing memory consumption by loading only the required portion of data at a time.
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().page(2, 12)).then((e) => {
items.value = e.result;
});
});
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: []
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().page(2, 12)).then((e) => {
this.items = e.result;
});
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>Aggregation
The aggregate method in the Query class computes statistical summaries such as sum, average, count, minimum, and maximum for specified fields within a dataset. This enables concise metric derivation, supporting analytical evaluation and reporting without requiring manual calculations.
The built-in aggregate types are,
- sum
- average
- min
- max
- count
- truecount
- falsecount
<template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Sum: {{sum}}</td>
<td></td>
</tr>
</table>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
const items = ref([]);
const sum = ref(0);
onMounted(() => {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().take(8).requiresCount()
.aggregate('sum', 'EmployeeID')).then((e) => {
items.value = e.result;
sum.value = e.aggregates['EmployeeID - sum'];
}
);
});
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style><template>
<div id="app">
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr v-for="(item, index) in items" :key="index">
<td>{{ item.OrderID }}</td>
<td>{{ item.CustomerID }}</td>
<td>{{ item.EmployeeID }}</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Sum: {{sum}}</td>
<td></td>
</tr>
</table>
</div>
</template>
<script>
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
export default {
data() {
return {
items: [],
sum: 0
};
},
mounted() {
let SERVICE_URI = "https://services.odata.org/V4/Northwind/Northwind.svc/Orders";
let dataManager = new DataManager({
url: SERVICE_URI,
adaptor: new ODataV4Adaptor()
});
dataManager.executeQuery(new Query().take(8).requiresCount()
.aggregate('sum', 'EmployeeID')).then((e) => {
this.items = e.result;
this.sum = e.aggregates['EmployeeID - sum'];
}
);
}
}
</script>
<style>
.e-table {
border: solid 1px #e0e0e0;
border-collapse: collapse;
font-family: Roboto;
}
.e-table td, .e-table th {
border-style: solid;
border-width: 1px 0 0;
border-color: #e0e0e0;
display: table-cell;
font-size: 14px;
line-height: 20px;
overflow: hidden;
padding: 8px 21px;
vertical-align: middle;
white-space: nowrap;
width: auto;
}
</style>