Two filtering approaches — server-side custom filters & client-side fixed searches
Each button swaps the Ajax endpoint. The server applies a MongoDB query via keyword arguments — DataTables(db, 'records', data, genre='Jazz'). Notice recordsTotal changes — this is a true server-side filter, not a client search.
Named fixed searches stack as AND conditions. Each has a unique name so they don't overwrite each other. Toggle multiple to combine. With serverSide: true, these are sent in the request and processed by mongo-datatables.
| Artist | Title | Label | Year | Genre | Format | Rating |
|---|
Fixed searches are injected manually into the Ajax data callback as columns[i].searchFixed (global) or searchFixed (table-level) — a dict keyed by name.
mongo-datatables reads both formats and applies each term as an additional $match condition.
// Client: inject via Ajax data callback
ajax: { data: function(d) {
d.columns[7].searchFixed = {
essential: active ? '4|' : undefined
};
}}
// Server reads columns[7].searchFixed:
// { "essential": "4|" }
// → { "rating": { "$gte": 4 } }
Genre buttons swap the Ajax URL. Each endpoint passes keyword arguments to the DataTables constructor — these become a $match stage prepended to every pipeline.
Because the filter is applied server-side, recordsTotal reflects only the filtered subset.
# /api/records/genre/jazz route:
DataTables(db, 'records', data,
data_fields=FIELDS,
genre='Jazz')
# Equivalent to prepending:
# { "$match": { "genre": "Jazz" } }