cancel
Showing results for 
Search instead for 
Did you mean: 

how to enable regular expression search on FilterOperator in sap ui5

former_member557181
Discoverer
0 Kudos

Hi Team,

Kindly help me is any way we can enable regular expression search on FilterOperator in sap ui5

My code looks like :

var aFilter = [];
var sQuery = oEvent.getParameter("query");
if (sQuery) {
aFilter.push(new Filter({
filters: [
new Filter("serverName", FilterOperator.Contains, sQuery),
new Filter("cbranch", FilterOperator.Contains, sQuery),
new Filter("bundleId", FilterOperator.Contains, sQuery),
new Filter("status", FilterOperator.Contains, sQuery),
new Filter("description", FilterOperator.Contains, sQuery),
new Filter("submitTime", FilterOperator.Contains, sQuery),
new Filter("owner", FilterOperator.Contains, sQuery),
new Filter("clno", FilterOperator.EQ, sQuery)

]
}));
}

// filter binding
var oList = this.byId("consDisplayChangesTable");
var oBinding = oList.getBinding("items");
oBinding.filter(aFilter);

Regards,

Lavanya

View Entire Topic
christian_mahr
Explorer
0 Kudos

Hi Lavanya,

if the Model is JSONModel it is possible, too: Here is a module and its caller, "ResourceModel" is the path of the query:

new RegexFilter("ResourceModel", query)
import Filter from "sap/ui/model/Filter";

export default class RegexFilter extends Filter {
    private query:string;
    constructor(path: string, query:string) {
        super({path:path, test: (p1: string ) => {
            const coreRegexMatch:string[]|undefined = this.query.match(/\/(.*)\//);
            if (coreRegexMatch) {
                return new RegExp(coreRegexMatch[1],"i").test(p1)
            } else {
                return p1.includes(this.query.toUpperCase())
            }
        }});
        this.query = query;
    }
}