Complex multi-condition queries with nested AND/OR — built client-side, executed server-side
Presets are hardcoded SearchBuilder criteria trees — clicking one is equivalent to building the same query manually in the UI above.
| Artist | Title | Label | Year | Genre | Format | Rating |
|---|
Each preset is a plain object with the same shape SearchBuilder uses in its Ajax payload — a logic field and a criteria array. When clicked, it's injected into the outgoing request via a preXhr handler using Object.defineProperty to prevent SearchBuilder from overwriting it.
// "1970s Jazz" preset object:
{
logic: 'AND',
criteria: [
{ origData: 'genre', condition: '=', value: ['Jazz'] },
{ origData: 'year', condition: 'between', value: ['1970', '1979'] }
]
}
// Injected into every Ajax request when active:
api.on('preXhr.preset', function(e, s, data) {
Object.defineProperty(data, 'searchBuilder',
{ get: () => preset, set: () => {} });
});
The library walks the searchBuilder criteria tree recursively.
Each condition maps to a MongoDB operator: "Equals" → $eq, "Between" → $gte/$lte, "Contains" → $regex.
Groups with logic: "AND" become $and, "OR" becomes $or.
Column types string, number, date, html-num, and html-num-fmt are all handled.
# "1970s Jazz" preset becomes:
{ "$and": [
{ "genre": { "$eq": "Jazz" } },
{ "year": { "$gte": 1970, "$lte": 1979 } }
]}