Querying in Angular Data component
30 Apr 202424 minutes to read
In this section, you will see in detail about how to build query using Query
class and consume
the data source.
Specifying resource name using from
The from
method is used to specify the resource name or table name from where the data should be retrieved.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().from('Orders').take(8)).then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Projection using select
The select
method is used to select particular fields or columns from the data source.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().select(['OrderID', 'CustomerID', 'EmployeeID']).take(8))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Eager loading navigation properties
You can use the expand
method to eagerly load navigation properties. The navigation properties
values are accessed using appropriate field names separated by dot(.) sign.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI })
.executeQuery(new Query().expand('Employee').select(['OrderID', 'CustomerID', 'Employee.FirstName']).take(8))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee Name</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Sorting
You can use the sortBy
method to perform sort operation in the
data source. Default sorting order is ascending. To change the sort order, either you can
specify the second argument of sortBy
as descending or use the
sortByDesc
method.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI: string = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor})
.executeQuery(new Query().sortBy('CustomerID', 'descending').take(8))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Multi sorting can be performed by simply chaining the multiple
sortBy
methods.
Filtering
You can use the where
method to build filter criteria which allows you to get reduced view of
records. The where
method can also be chained to form multiple filter criteria.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().sortBy('CustomerID', 'descending').take(8))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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
where
method andPredicate
class.
Build complex filter criteria using Predicate
Sometimes chaining where
method is not sufficient to create very
complex filter criteria, in such cases we can use Predicate
class to create composite filter criteria.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, Predicate, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
let predicate: Predicate = new Predicate('EmployeeID', 'equal', 3);
predicate = predicate.or('EmployeeID', 'equal', 2);
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().where(predicate).take(8))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Searching
You can use the search
method to create search criteria, it
differs from the filter in the way that search criteria will applied to all fields in the data
source whereas filter criteria will be applied to a particular field.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ReturnOption } from '@syncfusion/ej2-data';
import { data } from './datasource';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager(data as JSON[])
.executeQuery(new Query().search('VI', ['CustomerID']))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
You can search particular fields by passing the field name collection in the second argument of
search
method.
Grouping
DataManager
allow you to group records by category. The
group
method is used to add group query.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[];
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().group('CustomerID').take(8))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table' >
<tr>
<th>Order ID</th>
<th>Customer ID</th>
<th>Employee ID</th>
</tr>
<tbody group *ngFor="let item of items" [data]='item' ></tbody>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Multiple grouping can be done by simply chaining the
group
method.
Paging
You can query paged data using page
method. This allow you to query
particular set of records based on the page size and index.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().page(2, 6))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Aggregation
The aggregate
method allows you to get aggregated value for a field based on the type.
The built-in aggregate types are,
- sum
- average
- min
- max
- count
- truecount
- falsecount
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public min = 0;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().take(5).requiresCount().aggregate('min', 'EmployeeID'))
.then((e: ReturnOption) => { this.items = e.result as object[]; this.min = (e as any).aggregates['EmployeeID - min']; }).catch((e) => true);
}
}
<table class='e-table'>
<tr><th>Order ID</th><th>Customer ID</th><th>Employee ID</th></tr>
<tr *ngFor="let item of items">
<td></td><td></td><td></td>
</tr>
<tr><td></td><td></td><td>Min: content<h1 id="qrcodegenerator-in-angular-barcode-component">Qrcodegenerator in Angular Barcode component</h1>
<h2 id="qr-code">QR Code</h2>
<p>A QR Code is a two-dimensional barcode that consists of a grid of dark and light dots or blocks that form a square. The data encoded in the barcode can be numeric, alphanumeric, or Shift Japanese Industrial Standards (JIS8) characters. The QR Code uses version from 1 to 40. Version 1 measures 21 modules x 21 modules, Version 2 measures 25 modules x 25 modules, and so on. The number of modules increases in steps of 4 modules per side up to Version 40 that measures 177 modules x 177 modules. Each version has its own capacity. By default, the barcode control automatically set the version according to the length of the input text. The QR Barcodes are designed for industrial uses and also commonly used in consumer advertising.</p>
<div class="tabs" id="code-snippet-1">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class=""><a data-target="#3p39e1sqxxsr61cqh09k8rpvduxdkyyy-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">app.component.ts</a></li>
<li role="presentation" class=""><a data-target="#hmzfkggd0aol2xad6i34m4p9j41ece2w-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">main.ts</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="3p39e1sqxxsr61cqh09k8rpvduxdkyyy-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">NgModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/core'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BrowserModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span><span class="nx">QRCodeGeneratorAllModule</span><span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@syncfusion/ej2-angular-barcode-generator'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">Component</span> <span class="p">}</span> <span class="kr">from</span> <span class="s2">"@angular/core"</span><span class="p">;</span>
<span class="kd">@Component</span><span class="p">({</span>
<span class="nx">imports</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span> <span class="nx">QRCodeGeneratorAllModule</span> <span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span>
<span class="p">],</span>
<span class="nx">providers</span><span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
<span class="nx">standalone</span>: <span class="kt">true</span><span class="p">,</span>
<span class="nx">selector</span><span class="o">:</span> <span class="s2">"app-container"</span><span class="p">,</span>
<span class="c1">// specifies the template string for the barcode generator component</span>
<span class="nx">template</span><span class="o">:</span> <span class="sb">`<ejs-qrcodegenerator style="display: block;" #barcode id="barcode" width="200px" height="150px" mode="SVG" value="Syncfusion"></ejs-qrcodegenerator>`</span>
<span class="p">})</span>
<span class="k">export</span> <span class="kd">class</span> <span class="nx">AppComponent</span> <span class="p">{}</span></code></pre></div>
</div>
<div role="tabpanel" class="tab-pane" id="hmzfkggd0aol2xad6i34m4p9j41ece2w-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">bootstrapApplication</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">AppComponent</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'./app.component'</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">'zone.js'</span><span class="p">;</span>
<span class="nx">bootstrapApplication</span><span class="p">(</span><span class="nx">AppComponent</span><span class="p">).</span><span class="k">catch</span><span class="p">((</span><span class="nx">err</span><span class="p">)</span> <span class="p">=></span> <span class="nx">console</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="nx">err</span><span class="p">));</span></code></pre></div>
</div>
</div>
</div>
<p><button class="preview-sample-button" id="PreviewSampleButton-xtgnsx05ko30bbun2to699yheggjrql2" onclick="LoadPreviewSample('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/qrcode-cs1',this.id);">Preview Sample</button><button class="stackblitz-button" id="StackBlitzButton-xtgnsx05ko30bbun2to699yheggjrql2" onclick="OpenSampleInStackBlitz('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/qrcode-cs1');"><img class="stackblitz-icon" src="https://cdn.syncfusion.com/documentation/images/StackBlitz-icon.png"><span class="stackblitz-text">Open in Stackblitz</span></button></p>
<div id="PreviewSampleHolder-xtgnsx05ko30bbun2to699yheggjrql2"></div>
<h2 id="customizing-the-barcode-color">Customizing the Barcode color</h2>
<p>A page or printed media with barcode often appears colorful in the background and surrounding region with other contents. In such cases the barcode can also be customized to suit the needs. You can achieve this by using for forecolor property .</p>
<div class="tabs" id="code-snippet-2">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class=""><a data-target="#9mdvigw0sjtsq8wyyci5tqxiyey4wyly-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">app.component.ts</a></li>
<li role="presentation" class=""><a data-target="#ussu8yibeucwums0zj94s2snb0hw32y8-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">main.ts</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="9mdvigw0sjtsq8wyyci5tqxiyey4wyly-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">NgModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/core'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BrowserModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span><span class="nx">QRCodeGeneratorAllModule</span><span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@syncfusion/ej2-angular-barcode-generator'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">Component</span> <span class="p">}</span> <span class="kr">from</span> <span class="s2">"@angular/core"</span><span class="p">;</span>
<span class="kd">@Component</span><span class="p">({</span>
<span class="nx">imports</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span> <span class="nx">QRCodeGeneratorAllModule</span> <span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span>
<span class="p">],</span>
<span class="nx">providers</span><span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
<span class="nx">standalone</span>: <span class="kt">true</span><span class="p">,</span>
<span class="nx">selector</span><span class="o">:</span> <span class="s2">"app-container"</span><span class="p">,</span>
<span class="c1">// specifies the template string for the barcode generator component</span>
<span class="nx">template</span><span class="o">:</span> <span class="sb">`<ejs-qrcodegenerator style="display: block;" #barcode id="barcode" width="200px" foreColor="red" height="150px" mode="SVG" value="Syncfusion"></ejs-qrcodegenerator>`</span>
<span class="p">})</span>
<span class="k">export</span> <span class="kd">class</span> <span class="nx">AppComponent</span> <span class="p">{}</span></code></pre></div>
</div>
<div role="tabpanel" class="tab-pane" id="ussu8yibeucwums0zj94s2snb0hw32y8-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">bootstrapApplication</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">AppComponent</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'./app.component'</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">'zone.js'</span><span class="p">;</span>
<span class="nx">bootstrapApplication</span><span class="p">(</span><span class="nx">AppComponent</span><span class="p">).</span><span class="k">catch</span><span class="p">((</span><span class="nx">err</span><span class="p">)</span> <span class="p">=></span> <span class="nx">console</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="nx">err</span><span class="p">));</span></code></pre></div>
</div>
</div>
</div>
<p><button class="preview-sample-button" id="PreviewSampleButton-8hjg9u6phib0ivl55hyc0lhmv0x39gcv" onclick="LoadPreviewSample('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/color-cs1',this.id);">Preview Sample</button><button class="stackblitz-button" id="StackBlitzButton-8hjg9u6phib0ivl55hyc0lhmv0x39gcv" onclick="OpenSampleInStackBlitz('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/color-cs1');"><img class="stackblitz-icon" src="https://cdn.syncfusion.com/documentation/images/StackBlitz-icon.png"><span class="stackblitz-text">Open in Stackblitz</span></button></p>
<div id="PreviewSampleHolder-8hjg9u6phib0ivl55hyc0lhmv0x39gcv"></div>
<h2 id="customizing-the-barcode-dimension">Customizing the Barcode dimension</h2>
<p>The dimension of the barcode can be changed using the height and width properties of the barcodegenerator.</p>
<div class="tabs" id="code-snippet-3">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class=""><a data-target="#r60crsdz3t6273kc9so51lznyykkn0lm-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">app.component.ts</a></li>
<li role="presentation" class=""><a data-target="#7vvply2rpcsqsqfupcd28og5eh1acjaw-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">main.ts</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="r60crsdz3t6273kc9so51lznyykkn0lm-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">NgModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/core'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BrowserModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span><span class="nx">QRCodeGeneratorAllModule</span><span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@syncfusion/ej2-angular-barcode-generator'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">Component</span> <span class="p">}</span> <span class="kr">from</span> <span class="s2">"@angular/core"</span><span class="p">;</span>
<span class="kd">@Component</span><span class="p">({</span>
<span class="nx">imports</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span> <span class="nx">QRCodeGeneratorAllModule</span> <span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span>
<span class="p">],</span>
<span class="nx">providers</span><span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
<span class="nx">standalone</span>: <span class="kt">true</span><span class="p">,</span>
<span class="nx">selector</span><span class="o">:</span> <span class="s2">"app-container"</span><span class="p">,</span>
<span class="c1">// specifies the template string for the barcode generator component</span>
<span class="nx">template</span><span class="o">:</span> <span class="sb">`<ejs-qrcodegenerator style="display: block;" #barcode id="barcode" width="300px" height="300px" mode="SVG" value="Syncfusion"></ejs-qrcodegenerator>`</span>
<span class="p">})</span>
<span class="k">export</span> <span class="kd">class</span> <span class="nx">AppComponent</span> <span class="p">{}</span></code></pre></div>
</div>
<div role="tabpanel" class="tab-pane" id="7vvply2rpcsqsqfupcd28og5eh1acjaw-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">bootstrapApplication</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">AppComponent</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'./app.component'</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">'zone.js'</span><span class="p">;</span>
<span class="nx">bootstrapApplication</span><span class="p">(</span><span class="nx">AppComponent</span><span class="p">).</span><span class="k">catch</span><span class="p">((</span><span class="nx">err</span><span class="p">)</span> <span class="p">=></span> <span class="nx">console</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="nx">err</span><span class="p">));</span></code></pre></div>
</div>
</div>
</div>
<p><button class="preview-sample-button" id="PreviewSampleButton-dzld07p5uz0bzhl10je5iyd5o2uisznj" onclick="LoadPreviewSample('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/dimension-cs1',this.id);">Preview Sample</button><button class="stackblitz-button" id="StackBlitzButton-dzld07p5uz0bzhl10je5iyd5o2uisznj" onclick="OpenSampleInStackBlitz('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/dimension-cs1');"><img class="stackblitz-icon" src="https://cdn.syncfusion.com/documentation/images/StackBlitz-icon.png"><span class="stackblitz-text">Open in Stackblitz</span></button></p>
<div id="PreviewSampleHolder-dzld07p5uz0bzhl10je5iyd5o2uisznj"></div>
<h2 id="customizing-the-text">Customizing the text</h2>
<p>In barcode generators You can customize the barcode text by using display text property .</p>
<div class="tabs" id="code-snippet-4">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class=""><a data-target="#go1d8f228ok3xqonpyqyvbnyj4hij61k-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">app.component.ts</a></li>
<li role="presentation" class=""><a data-target="#2xnfxax2w99a51f9jlcjwqex1o8yra3t-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">main.ts</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="go1d8f228ok3xqonpyqyvbnyj4hij61k-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">NgModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/core'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BrowserModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span><span class="nx">QRCodeGeneratorAllModule</span><span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@syncfusion/ej2-angular-barcode-generator'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">Component</span> <span class="p">,</span><span class="nx">ViewChild</span><span class="p">}</span> <span class="kr">from</span> <span class="s2">"@angular/core"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BarcodeGeneratorComponent</span><span class="p">,</span><span class="nx">DisplayTextModel</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@syncfusion/ej2-angular-barcode-generator'</span><span class="p">;</span>
<span class="kd">@Component</span><span class="p">({</span>
<span class="nx">imports</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span> <span class="nx">QRCodeGeneratorAllModule</span> <span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span>
<span class="p">],</span>
<span class="nx">providers</span><span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
<span class="nx">standalone</span>: <span class="kt">true</span><span class="p">,</span>
<span class="nx">selector</span><span class="o">:</span> <span class="s2">"app-container"</span><span class="p">,</span>
<span class="c1">// specifies the template string for the barcode generator component</span>
<span class="nx">template</span><span class="o">:</span> <span class="sb">`<ejs-qrcodegenerator style="display: block;" #barcode id="barcode" width="200px" height="150px" [displayText] = 'displayText' mode="SVG" value="Syncfusion"></ejs-qrcodegenerator>`</span>
<span class="p">})</span>
<span class="k">export</span> <span class="kd">class</span> <span class="nx">AppComponent</span> <span class="p">{</span>
<span class="c1">// @ViewChild('barcode')</span>
<span class="kd">@ViewChild</span><span class="p">(</span><span class="s1">'displayText'</span><span class="p">)</span>
<span class="k">public</span> <span class="nx">displayText?</span>: <span class="kt">DisplayTextModel</span><span class="p">;</span>
<span class="nx">ngOnInit</span><span class="p">()</span><span class="o">:</span> <span class="ow">void</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">displayText</span> <span class="o">=</span> <span class="p">{</span>
<span class="nx">text</span><span class="o">:</span><span class="s1">'text'</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></div>
</div>
<div role="tabpanel" class="tab-pane" id="2xnfxax2w99a51f9jlcjwqex1o8yra3t-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">bootstrapApplication</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">AppComponent</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'./app.component'</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">'zone.js'</span><span class="p">;</span>
<span class="nx">bootstrapApplication</span><span class="p">(</span><span class="nx">AppComponent</span><span class="p">).</span><span class="k">catch</span><span class="p">((</span><span class="nx">err</span><span class="p">)</span> <span class="p">=></span> <span class="nx">console</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="nx">err</span><span class="p">));</span></code></pre></div>
</div>
</div>
</div>
<p><button class="preview-sample-button" id="PreviewSampleButton-ex43x6k3z1tak5rq4f9lu0qetz4rt3yc" onclick="LoadPreviewSample('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/text-cs1',this.id);">Preview Sample</button><button class="stackblitz-button" id="StackBlitzButton-ex43x6k3z1tak5rq4f9lu0qetz4rt3yc" onclick="OpenSampleInStackBlitz('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/text-cs1');"><img class="stackblitz-icon" src="https://cdn.syncfusion.com/documentation/images/StackBlitz-icon.png"><span class="stackblitz-text">Open in Stackblitz</span></button></p>
<div id="PreviewSampleHolder-ex43x6k3z1tak5rq4f9lu0qetz4rt3yc"></div>
<h2 id="enhancing-qr-codes-with-icons">Enhancing QR Codes with Icons</h2>
<p>The EJ2 Barcode Generator now lets you add a <a href="https://ej2.syncfusion.com/angular/documentation/api/barcode/qRCodeLogo/"><code>logo</code></a> or icon to your QR codes, boosting their visual appeal, clarity, and even security. Adding a recognizable icon can make it easier for users to identify the source and can help prevent tampering .</p>
<h3 id="supported-image-sources">Supported Image Sources</h3>
<p>The <a href="https://ej2.syncfusion.com/angular/documentation/api/barcode/qRCodeLogo/#imagesource"><code>imageSource</code></a> property of the <code>QRCodeLogo</code> class supports the following image sources:</p>
<ul>
<li>
<strong>Local image path</strong>: Specify the path to the image file relative to your project’s root directory (e.g., <code>images/syncfusion.png</code>) or as an absolute path (e.g., <code>/assets/icons/logo.svg</code>).</li>
<li>
<strong>Remote image URL</strong>: Provide the web address of the image file (e.g., <code>https://example.com/image.jpg</code>).</li>
<li>
<strong>Base64 encoded image data</strong>: Embed the image data directly in the code using a Base64-encoded string (e.g., <code>data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...</code>).</li>
</ul>
<h3 id="logo-dimensions">Logo Dimensions</h3>
<p>The <a href="https://ej2.syncfusion.com/angular/documentation/api/barcode/qRCodeLogo/#width"><code>width</code></a> and <a href="https://ej2.syncfusion.com/angular/documentation/api/barcode/qRCodeLogo/#height"><code>height</code></a> properties of the <code>QRCodeLogo</code> class define the dimensions of the logo in pixels. If not specified, both default to 30% of the QR code’s size. The maximum allowed size is 30% of the QR code’s dimensions to ensure optimal readability.</p>
<p><strong>Note:</strong> Always test the readability of your QR code after adding a logo. Depending on the logo size and QR code content, you might need to adjust the <a href="https://ej2.syncfusion.com/angular/documentation/api/barcode/errorCorrectionLevel/"><code>errorCorrectionLevel</code></a> property of the <code>QRCodeGenerator</code> to <code>"Medium"</code> or <code>"High"</code> for better reliability.</p>
<p>The following image illustrates QR code with logo:</p>
<p><img src="images/logo.png" alt="logo"></p>
<div class="tabs" id="code-snippet-5">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class=""><a data-target="#mlpwm0itg2ie4mkrnka29e1mzvwhsms9-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">app.component.ts</a></li>
<li role="presentation" class=""><a data-target="#ql6ujisav8okkbx1z0sbi1bl10i94ckw-ts" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="ts">main.ts</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="mlpwm0itg2ie4mkrnka29e1mzvwhsms9-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">NgModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/core'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BrowserModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span><span class="nx">QRCodeGeneratorAllModule</span><span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@syncfusion/ej2-angular-barcode-generator'</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">Component</span> <span class="p">,</span><span class="nx">ViewChild</span><span class="p">}</span> <span class="kr">from</span> <span class="s2">"@angular/core"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BarcodeGeneratorComponent</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@syncfusion/ej2-angular-barcode-generator'</span><span class="p">;</span>
<span class="kd">@Component</span><span class="p">({</span>
<span class="nx">imports</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">BarcodeGeneratorAllModule</span><span class="p">,</span> <span class="nx">QRCodeGeneratorAllModule</span> <span class="p">,</span><span class="nx">DataMatrixGeneratorAllModule</span>
<span class="p">],</span>
<span class="nx">providers</span><span class="o">:</span> <span class="p">[</span> <span class="p">],</span>
<span class="nx">standalone</span>: <span class="kt">true</span><span class="p">,</span>
<span class="nx">selector</span><span class="o">:</span> <span class="s2">"app-container"</span><span class="p">,</span>
<span class="c1">// specifies the template string for the barcode generator component</span>
<span class="nx">template</span><span class="o">:</span> <span class="sb">`<ejs-qrcodegenerator style="display: block;" #barcode id="barcode" width="200px" height="150px" [logo] = 'logo' mode="SVG" value="Syncfusion"></ejs-qrcodegenerator>`</span>
<span class="p">})</span>
<span class="k">export</span> <span class="kd">class</span> <span class="nx">AppComponent</span> <span class="p">{</span>
<span class="c1">// @ViewChild('barcode')</span>
<span class="kd">@ViewChild</span><span class="p">(</span><span class="s1">'logo'</span><span class="p">)</span>
<span class="k">public</span> <span class="nx">logo?</span>: <span class="kt">any</span><span class="p">;</span>
<span class="nx">ngOnInit</span><span class="p">()</span><span class="o">:</span> <span class="ow">void</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">logo</span> <span class="o">=</span> <span class="p">{</span>
<span class="nx">imageSource</span><span class="o">:</span><span class="s1">'https://www.syncfusion.com/web-stories/wp-content/uploads/sites/2/2022/02/cropped-Syncfusion-logo.png'</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></div>
</div>
<div role="tabpanel" class="tab-pane" id="ql6ujisav8okkbx1z0sbi1bl10i94ckw-ts" data-original-lang="ts">
<div class="highlight"><pre><code class="prettyprint language-ts" data-lang="ts"><span></span><span class="k">import</span> <span class="p">{</span> <span class="nx">bootstrapApplication</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'@angular/platform-browser'</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">AppComponent</span> <span class="p">}</span> <span class="kr">from</span> <span class="s1">'./app.component'</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">'zone.js'</span><span class="p">;</span>
<span class="nx">bootstrapApplication</span><span class="p">(</span><span class="nx">AppComponent</span><span class="p">).</span><span class="k">catch</span><span class="p">((</span><span class="nx">err</span><span class="p">)</span> <span class="p">=></span> <span class="nx">console</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="nx">err</span><span class="p">));</span></code></pre></div>
</div>
</div>
</div>
<p><button class="preview-sample-button" id="PreviewSampleButton-iedm2z4j2ypx08l5erz081wicglcfu0v" onclick="LoadPreviewSample('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/logo-cs1',this.id);">Preview Sample</button><button class="stackblitz-button" id="StackBlitzButton-iedm2z4j2ypx08l5erz081wicglcfu0v" onclick="OpenSampleInStackBlitz('https://helpej2.syncfusion.com/angular/documentation/samples/barcode/qrcode/logo-cs1');"><img class="stackblitz-icon" src="https://cdn.syncfusion.com/documentation/images/StackBlitz-icon.png"><span class="stackblitz-text">Open in Stackblitz</span></button></p>
<div id="PreviewSampleHolder-iedm2z4j2ypx08l5erz081wicglcfu0v"></div>
</td></tr>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Hierarchical query
You can use the hierarchy
method to build nested query.
The hierarchical queries are commonly required when you use foreign key binding.
The foreignKey
method is used to specify the key field of the
foreign table and the second argument of the hierarchy
method
accepts a selector function which selects the records from the foreign table.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Component, OnInit } from '@angular/core';
import { DataManager, Query, ODataAdaptor, ReturnOption } from '@syncfusion/ej2-data';
const SERVICE_URI = 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.template.html',
styles: [`
.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;
}
`]
})
export class AppComponent implements OnInit {
public items?: object[] | any;
public ngOnInit(): void {
new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor()})
.executeQuery(new Query().from('Orders').take(3).hierarchy(
new Query()
.foreignKey('OrderID')
.from('Order_Details')
.sortBy('Quantity'),
() => [10248, 10249, 10250] // Selective loading of child elements
))
.then((e: ReturnOption) => this.items = e.result as object[]).catch((e) => true);
}
}
<table class='e-table'>
<tr>
<th>Order ID</th>
<th>Customer ID</th>
<th>Employee ID</th>
</tr>
<tbody *ngFor="let item of items">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="3">
<table class='e-table'>
<tr>
<th>ID</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<tbody *ngFor="let order of item.Order_Details">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));