Request: Filter option in column headers
Hi
I'd like to see filter options in the column headers of all table views. Currently you can sort on all column headers, which is good, but it would be good to be able to filter on each one as well.
Such as being able to show only items with a category "Apple Macbook" with a purchase date of 2015.
Olly
Just signed up to second this--I've been using Snipe IT for a few months now and love it...having the ability to granularly filter data rather than sorting alone would be a huge plus.
I work for a K-8 school district and we've got about 7,000 assets (always growing too). I can search by location or model, etc to limit things somewhat, but the ability to combine searches/filters would be so incredibly helpful for me and my staff.
-Rob
I would also appreciate this feature.
Agreed. Would like to see this feature.
We all would. Unfortunately, the javascript library we use for data tables is a little wonky with this stuff when it's server-side sorting.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!
I hate to reopen an old issue but since it was closed as stale, I'd like to query on if this would be possible? I would like to be able to search for all assets with 'hp' but where the serial number is blank or purchase/warranty date is blank/below a certain value. Can this be done with the current version or v5?
Also interested in the feature will it ever happen? Would be extremely useful to filter by date for licenses to track renewals, or at least have a generic custom report that's not just for assets!
This feature is crucial to using SnipeIT. As a new user, I am very surprised that SnipeIT has no way of drilling down into categories and filtering views. If the norm is to wade into several thousands of rows of data to find a category associated to an asset, then it's nearly impossible to use.
The only alternative is to bookmark the Categories setup page which at least allows you to drill into a specific category and view assets associated with it.
I hate to reopen an old issue but since it was closed as stale, I'd like to query on if this would be possible? I would like to be able to search for all assets with 'hp' but where the serial number is blank or purchase/warranty date is blank/below a certain value. Can this be done with the current version or v5?
I think it should be possible. I recently added a column filter for assets listing that's somewhat configurable (filter types, filter key, etc).
I can't believe I'm commenting on something like this again in 2025, but shouldn't this be a standard feature? I hate having to export the assets to Excel every time and filter and search there for what I need. I got SnipeIT to replace Excel, not to have to keep searching for everything in Excel.
I can't believe I'm commenting on something like this again in 2025,
Yeah, me either.
If it was simple to do, we would have done it. We have to worry about more than just your implementation. How different localizations affect the UI, etc. The js library we use does support filters on headers, but the UX is generally terrible, and it conflicts with other libraries.
That said, we welcome your pull request.
@amiraiman If you'd like to share that code, we can see what we can do with it to move this forward. The current BS tables implementation still looks awful and doesn't seem to work very well, at least not with server-side data.
@amiraiman - just a follow up here - would you be able to share that code?
@snipe - I use bootstrap table filter extension for the column filters. It's already included in the bootstrap-table npm module installed in this project, so I just had to update the webpack.mix.js to include it in the project.
As for the filter usage, I added data-filter-control="true" to the table element that I want to have the column filter on to enable it, then I include the necessary column options attributes (i.e data-filter-control & data-filter-data) through AppPresenter and filter them in the model's query scope filter method scopeByFilter().
For instance to add a select column filter on the Assets table to be able to filter the assets by each individual Asset Model, I did the following changes:
One-time changes:
- Include the extension in webpack
- In the API
app/Http/Controllers//Api/AssetsController.php@ line 151, I changed the conditionals to allow filtering & searching at the same time.
if ($request->filled('search')) {
$assets->TextSearch($request->input('search'));
}
if ((!is_null($filter)) && (count($filter) > 0)) {
$assets->ByFilter($filter);
}
- Add the
data-filter-control="true"&data-filter-field-key-map="tableColumnName:dbColumnName"toresources/views/hardware/index.blade.php. - Update
queryParamsprocessing inresources/views/partials/bootstrap-table.blade.php. This is where i use thedata-filter-field-key-mapattribute (a custom attribute I made up, nothing to do with the extension) to bind the table column name set inAssetPresenterwith the actual db column name I'll be querying in the API. It's basically a comma separated list of 'tableColumnName:dbColumnName'. I.e if I have multiple column filters, the attribute would look likedata-filter-field-key-map="model:model_id,category:category_id". Then in thequeryParamsconfig, I would read the value and split it, loop through every pairs, and then update the query parameters to use the actual db column instead of the column name.
Changes for every column filter:
- Add table column & db column map to
data-filter-field-key-mapattribute inresources/views/hardware/index.blade.php. - Add the filterControl & filterData column attributes on
app/Presenters/AssetPresenter.php
[
'field' => 'model',
'filterControl' => "select",
'filterData' =>
"json:" . json_encode(
AssetModel::select(
[
'models.id',
'models.name',
]
)->get()
->mapWithKeys(fn ($item) => [$item->id => $item->name])
->toArray()
),
'searchable' => true,
'sortable' => true,
'title' => trans('admin/hardware/form.model'),
'visible' => true,
'formatter' => 'modelsLinkObjFormatter',
]
- Exclude the
model_idattribute from being searched globally & add themodel_idfilter clause in the query scope inapp/Models/Asset.php. I.e in thescopeByFilter($query, $filter)method, I inserted a new filter
if ($fieldname == 'model_id') {
$query->where(function ($query) use ($search_val) {
$query->whereHas('model', function ($query) use ($search_val) {
$query->where('models.id', '=', $search_val);
});
});
}
and then at the end exclude it in the global search scope
if (($fieldname!='category') && ($fieldname!='category_id') && ($fieldname!='model_number') && ($fieldname!='model_id') && ($fieldname!='rtd_location') && ($fieldname!='location') && ($fieldname!='supplier')
&& ($fieldname!='status_label') && ($fieldname!='status_label_id') && ($fieldname!='assigned_to') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) {
$query->where('assets.'.$fieldname, 'LIKE', '%' . $search_val .
}
P/S: I added this functionality to be used in our local instance of snipe-it, and it is only used by our SysAdmin and not our employees. I did not do any further testing / checks on data leakage through when adding the custom filter in the API request, etc since our SysAdmin has admin privileges and they are the sole user of the system
@amiraiman - thanks a ton for this explanation. I had attempted to use that extension as well, but it would never pick up the select2 (so it looked crappy) and of course we'll need to figure out how to handle access and such, but this is a big help! Much appreciated!
@snipe - no problem, glad I could help.
we'll need to figure out how to handle access and such
Yeah, I guess this is the hardest part of making this feature (access control, custom fields, filter types, etc). In my case, it's pretty much clear cut which columns they want a filter on, as well as what type of filter they would like so I could just hard coded those in the codebase, but when you need to dynamically generate those filters based on user input, it's definitely much more work than my proposed workaround.
Good luck!
Do you think in your experiments that we could implement the standard (access controlled) select2 lists here? vs this:
"json:" . json_encode(
AssetModel::select(
[
'models.id',
'models.name',
]
)->get()
->mapWithKeys(fn ($item) => [$item->id => $item->name])
->toArray()
),
We already have selectlist endpoints for all major models (locations. assets, companies, categories, etc). I haven't dug too much into this, but it would be a lot cleaner if we could re-use the same lists we use in the GUI