We have a grid that uses local array data source that is list of orders:
#grid [dataSource]='listOfOrders' [toolbar]='toolbarOptions' searchSettings="" (load)="onLoad()">
It also uses one foreign key column (and respective additional array data source that is list of users):
field='createdBy' foreignKeyField='id' foreignKeyValue='name' [dataSource]='listOfUsers'>
Based upon similar custom search implementations we tried to implement custom search.
Search should look for match (user by name) and get list of filtered users.
Then it should look for match (orders) or where user is one from users' list.
onLoad(): void {
// Keyup event bound to the input element
this.grid.element.addEventListener('keyup', (args: KeyboardEvent) => {
if ((args.target as HTMLElement).getAttribute('id') === 'toolSearch' && args.key === "Enter") {
let gridObj: Grid = this.grid;
let input: HTMLInputElement = (args.target as HTMLInputElement);
let filtUserIds = [];
// First filter users
let userPredicate = new Predicate('name', 'contains', input.value);
new DataManager({ json: this.listOfUsers }).executeQuery(new Query().select('íd').where(userPredicate)).then((e: ReturnOption) => {
filtUserIds = e.result as object[];
});
// Then filter orders by title or by user id
var orderPredicate = new Predicate('title', "contains", input.value).or('createdBy', 'in', filtUserIds);
new DataManager({ json: (gridObj.dataSource as object[]) }).executeQuery(new Query().where(orderPredicate)).then((e: ReturnOption) => {
// The returned result is assigned to the grid datasource
gridObj.dataSource = e.result as object[];
});
The problem is predicate does not support filtering by presence in list. There is no option for
.or('createdBy', 'in', filtUserIds);
It could be that we are looking in wrong direction here, but searching by foreign key value seems to be very common use case.
Are there are any valid alternatives to our approach please?