Filter Module
Reusable filtering system for grid selectors - supports set filters, range filters, search text, filter locking, and active filter calculation.
Reusable filtering system for grid selectors - supports set filters, range filters, search text, filter locking, and active filter calculation.
Overview
filterModule provides a factory that creates filter management instances. Filters can be set-based (checkboxes) or range-based (min/max sliders), with support for locking, common filter detection, and a dirty-flag optimization for recalculation.
Module path: lua/ge/extensions/ui/gridSelectorUtils/filterModule.lua (loaded via require)
Exports (M)
| Function | Signature | Description |
|---|---|---|
create | (createFn, commonFilters, rangeFilters, dictFilters, backendName, passesFn) | Creates a filter manager instance. |
Instance Methods
| Method | Signature | Description |
|---|---|---|
initializeFilters | (configList) | Initializes filters from item data. |
getFilters | () | Returns filter list, active filters, and locked state. |
toggleFilter | (propName, option) | Toggles a set filter option. |
updateRangeFilter | (propName, min, max) | Updates range filter bounds. |
resetSetFilter | (propName) | Resets all options to enabled. |
resetRangeFilter | (propName) | Resets range to original bounds. |
clearAllFilters | () | Resets all filters and search text. |
passesFilters | (item) | Tests if an item passes current filters. |
getSearchText / setSearchText | (text?) | Get/set search text. |
lockFilter | (propName, options?) | Locks filter options to prevent modification. |
unlockFilter | (propName, options?) | Unlocks locked filter options. |
lockFilterMode | (propName, options) | Sets and locks specific option values. |
lockFilterModeExclusive | (propName, allowedOptions) | Locks all options false except specified ones. |
clearLockedFilters | () | Removes all filter locks. |
Internals
Set Filter Toggle Logic
Toggle behavior adapts based on current state:
- All enabled → clicking one option enables only that option, disables others
- Mixed state → clicking flips that single option
- All disabled after toggle → resets all to enabled (prevents empty filter)
if allEnabled then
-- Enable only clicked, disable rest
for _, opt in ipairs(filter.options) do
filterByProp[propName][opt] = (opt == option)
end
else
filterByProp[propName][option] = not currentValue
endFilter Locking
Locked filters cannot be toggled/reset. Used when the selector is opened with pre-set constraints:
-- Lock to only show "Rally Stage" and "Rally Loop"
instance.lockFilterModeExclusive("type", {"Rally Stage", "Rally Loop"})
-- User can toggle between those two but not enable other typesActive Filter Calculation
Produces display-friendly summaries of what's filtered:
{
propName = "system",
displayText = "system Challenges",
isActive = true,
iconType = "checkmark",
type = "set"
}Dirty Flag Optimization
filtersDirty tracks when filters need recalculation. setupValidFilters() is only called when dirty, caching validFilters between checks.
How It Works
- Backend creates filter instance with a filter-creation function
initializeFilters(items)scans items to discover filter options- UI renders filters from
getFilters()and handles user interactions toggleFilter/updateRangeFiltermodify state and set dirty flagpassesFilters(item)checks item against cached valid filters + search text- Locked filters maintain pre-set constraints that users can't override
Additional Exports
The following exports are available but not yet documented in detail:
M.create