Manage the query filters
Level: intermediate
Example that manages the query filters
/* Create a query instance with the Contact root schema. */
var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "Contact"
});
esq.addColumn("Name");
esq.addColumn("Country.Name", "CountryName");
/* Create a first filter instance. */
var esqFirstFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Country.Name", "Spain");
/* Create a second filter instance. */
var esqSecondFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Country.Name", "France");
/* Combine the filters in the query filters collection using the OR logical operator. */
esq.filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
/* Add the filters to the query collection. */
esq.filters.add("esqFirstFilter", esqFirstFilter);
esq.filters.add("esqSecondFilter", esqSecondFilter);
/* Add the objects (query results) filtered by the two filters to the collection. */
esq.getEntityCollection(function (result) {
if (result.success) {
result.collection.each(function (item) {
/* Process the collection elements. */
});
}
}, this);
/* Specify that the second filter is not used to build the resulting query. At the same time, do not delete the filter from the query filters collection. */
esqSecondFilter.isEnabled = false;
/* Add the objects (query results) filtered only by the first filter to the collection. */
esq.getEntityCollection(function (result) {
if (result.success) {
result.collection.each(function (item) {
/* Process the collection elements. */
});
}
}, this);
Example that uses other filter creation methods
/* Create a query instance with the Contact root schema. */
var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "Contact"
});
esq.addColumn("Name");
esq.addColumn("Country.Name", "CountryName");
/* Select all contacts that do not have a country specified. */
var esqFirstFilter = esq.createColumnIsNullFilter("Country");
/* Select all contacts that have birth dates between 01.1.1970 and 01.1.1980. */
var dateFrom = new Date(1970, 0, 1, 0, 0, 0, 0);
var dateTo = new Date(1980, 0, 1, 0, 0, 0, 0);
var esqSecondFilter = esq.createColumnBetweenFilterWithParameters("BirthDate", dateFrom, dateTo);
/* Add the created filters to the query collection. */
esq.filters.add("esqFirstFilter", esqFirstFilter);
esq.filters.add("esqSecondFilter", esqSecondFilter);
/* Add the objects (query results) filtered by the two filters to the collection. */
esq.getEntityCollection(function (result) {
if (result.success) {
result.collection.each(function (item) {
/* Process the collection elements. */
});
}
}, this);