Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(query-builder-sample): update QB sample 1 with nested entities #3532

Merged
merged 6 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="wrapper">
<igx-query-builder #queryBuilder
[fields]="fields"
[entities]="entities"
[expressionTree]="expressionTree">
<igx-query-builder-header [title]="'Query Builder Overview'" [showLegend]="true">
</igx-query-builder-header>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,92 @@
import { Component, OnInit } from '@angular/core';
import { FilteringExpressionsTree, FilteringLogic, IExpressionTree, IgxQueryBuilderComponent, IgxStringFilteringOperand } from 'igniteui-angular';
import { FilteringExpressionsTree, FilteringLogic, IExpressionTree, IgxBooleanFilteringOperand, IgxDateFilteringOperand, IgxNumberFilteringOperand, IgxQueryBuilderComponent, IgxStringFilteringOperand } from 'igniteui-angular';
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved

@Component({
selector: 'app-query-builder-sample-1',
styleUrls: ['./query-builder-sample-1.component.scss'],
templateUrl: 'query-builder-sample-1.component.html'
})
export class QueryBuilderSample1Component implements OnInit {
public entities: Array<any>;
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved
public companiesFields: Array<any>;
public ordersFields: Array<any>;
public expressionTree: IExpressionTree;

public fields: any[] = [
{ field: 'ID', dataType: 'string' },
{ field: 'CompanyName', dataType: 'string' },
{ field: 'ContactName', dataType: 'string' },
{ field: 'Employees', dataType: 'number' },
{ field: 'ContactTitle', dataType: 'string' },
{ field: 'DateCreated', dataType: 'date' },
{ field: 'TimeCreated', dataType: 'time' },
{ field: 'Address', dataType: 'string' },
{ field: 'City', dataType: 'string' },
{ field: 'Region', dataType: 'string' },
{ field: 'PostalCode', dataType: 'string' },
{ field: 'Phone', dataType: 'string' },
{ field: 'Fax', dataType: 'string' },
{ field: 'Contract', dataType: 'boolean' }
];

public ngOnInit(): void {
const tree = new FilteringExpressionsTree(FilteringLogic.And);
tree.filteringOperands.push({
fieldName: 'ID',
condition: IgxStringFilteringOperand.instance().condition('contains'),
searchVal: 'a',
ignoreCase: true
this.companiesFields = [
{ field: "ID", dataType: "string" },
{ field: "CompanyName", dataType: "string" },
{ field: "ContactName", dataType: "string" },
{ field: "Employees", dataType: "number" },
{ field: "ContactTitle", dataType: "string" },
{ field: "DateCreated", dataType: "date" },
{ field: "TimeCreated", dataType: "time" },
{ field: "Address", dataType: "string" },
{ field: "City", dataType: "string" },
{ field: "Region", dataType: "string" },
{ field: "PostalCode", dataType: "string" },
{ field: "Phone", dataType: "string" },
{ field: "Fax", dataType: "string" },
{ field: "Contract", dataType: "boolean" },
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved
];

this.ordersFields = [
{ field: "CompanyID", dataType: "string" },
{ field: "OrderID", dataType: "number" },
{ field: "EmployeeId", dataType: "number" },
{ field: "OrderDate", dataType: "date" },
{ field: "RequiredDate", dataType: "date" },
{ field: "ShippedDate", dataType: "date" },
{ field: "ShipVia", dataType: "number" },
{ field: "Freight", dataType: "number" },
{ field: "ShipName", dataType: "string" },
{ field: "ShipCity", dataType: "string" },
{ field: "ShipPostalCode", dataType: "string" },
{ field: "ShipCountry", dataType: "string" },
{ field: "Region", dataType: "string" },
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved
];

this.entities = [
{
name: "Companies",
fields: this.companiesFields,
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "Orders",
fields: this.ordersFields,
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved
}
];

const innerTree = new FilteringExpressionsTree(FilteringLogic.And, undefined, 'Companies', ['ID']);
innerTree.filteringOperands.push({
fieldName: 'Employees',
condition: IgxNumberFilteringOperand.instance().condition('greaterThan'),
conditionName: 'greaterThan',
searchVal: 100,
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved
});
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
orTree.filteringOperands.push({
fieldName: 'ID',
condition: IgxStringFilteringOperand.instance().condition('contains'),
searchVal: 'b',
ignoreCase: true
innerTree.filteringOperands.push({
fieldName: 'Contact',
condition: IgxBooleanFilteringOperand.instance().condition('true'),
conditionName: 'true',
ivanvpetrov marked this conversation as resolved.
Show resolved Hide resolved
});
orTree.filteringOperands.push({
fieldName: 'CompanyName',
condition: IgxStringFilteringOperand.instance().condition('contains'),
searchVal: 'c',
ignoreCase: true

const tree = new FilteringExpressionsTree(FilteringLogic.And, undefined, 'Orders', ['*']);
tree.filteringOperands.push({
fieldName: 'CompanyID',
condition: IgxStringFilteringOperand.instance().condition('in'),
conditionName: 'in',
searchTree: innerTree
});
tree.filteringOperands.push({
fieldName: 'OrderDate',
condition: IgxDateFilteringOperand.instance().condition('before'),
conditionName: 'before',
searchVal: new Date('2024-01-01T00:00:00.000Z')
});
tree.filteringOperands.push(orTree);
tree.filteringOperands.push({
fieldName: 'CompanyName',
condition: IgxStringFilteringOperand.instance().condition('contains'),
searchVal: 'd',
ignoreCase: true
fieldName: 'ShippedDate',
condition: IgxDateFilteringOperand.instance().condition('null'),
conditionName: 'null'
});

this.expressionTree = tree;
Expand All @@ -61,4 +95,4 @@ export class QueryBuilderSample1Component implements OnInit {
public printExpressionTree(tree: IExpressionTree) {
return tree ? JSON.stringify(tree, null, 2) : 'Please add an expression!';
}
}
}
Loading