In my Angular Web App, I am utilizing the Azure Mobile Services library for JavaScript. The documentation states that there are two methods to filter returned data: passing a JSON object or using a filter function for more complex filtering. Since I need to use relational operators like greater than or less than for columns such as startDate or endDate, I have opted to use the filter function.
Currently, I have a function that generates a filter function based on various filters set on the front end. However, this function includes a series of if...else conditions to determine which filters are set and what filter function to return.
function getFilterFunc() {
if (x != null) {
if (y != null) {
return function () { return this.id == xyz && this.x == x && this.y == y; };
} else {
return function () { return this.id == xyz && this.x == x; };
}
}
.
.
.
else {
return function () { return this.id == xyz; };
}
}
This approach becomes cumbersome with multiple filters, prompting me to explore a more efficient method to generate the filter function. Perhaps by iterating through all the filters and concatenating the conditions into a single return statement for each set filter. This way, we can assemble the final filter function and apply it to Azure Mobile Services seamlessly.