ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Selectable Filter

Open wendeldw opened this issue 11 years ago • 8 comments

Feature request:

Extend the filter inputs with select boxes. Or some hints in how to implement it.

wendeldw avatar Feb 09 '15 17:02 wendeldw

What would the select boxes do? Or do you mean dropdowns?

PaulL1 avatar Feb 09 '15 18:02 PaulL1

Yes, dropdowns.

wendeldw avatar Feb 09 '15 18:02 wendeldw

OK, so where I'd start is by adding a new option (perhaps columnDef.filterOptions) into which you could put an array of { value, description }. I'd then modify the filter code to use a select instead of an input when a filterOptions array is provided, and put the resulting value after a selection into the filters object that the rowSearcher uses.

The code mostly lives in ui-grid-header-cell.js, templates/uiGridHeaderCell.html, and then services/rowSearcher.js. There's a contributing guide and a first time contributors guide that would probably help.

PaulL1 avatar Feb 09 '15 19:02 PaulL1

Nice feature

bleuscyther avatar Feb 10 '15 06:02 bleuscyther

I propose to close this issue in favor of the more generic request #2796.

ghost avatar Mar 05 '15 14:03 ghost

Using the existing APIs, was able to implement this feature by providing a headerCellTemplate for the column where it is required, in the following manner:

<div ng-class="{ 'sortable': sortable }">
    <div class="ui-grid-vertical-bar">&nbsp;</div>
    <div class="ui-grid-cell-contents" col-index="renderIndex">
        <span>{{ col.displayName CUSTOM_FILTERS }}</span> 
        <span ui-grid-visible="col.sort.direction" ng-class="{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }">&nbsp;</span>
    </div>
    <div class="ui-grid-column-menu-button" ng-if="grid.options.enableColumnMenus && !col.isRowHeader  && col.colDef.enableColumnMenu !== false" class="ui-grid-column-menu-button" ng-click="toggleMenu($event)">
        <i class="ui-grid-icon-angle-down">&nbsp;</i>
    </div>
    <div ng-if="filterable" class="ui-grid-filter-container" ng-repeat="colFilter in col.filters">
        <!-- here's the actual solution: replacing the original input control in the default headerCellTempalte with the a different control of your choice. -->
        <select class="ui-grid-filter-input" ng-model="colFilter.term" ng-options="status for status in getExternalScopes().alarmStatus" ng-click="$event.stopPropagation()"></select>
        <div class="ui-grid-filter-button" ng-click="colFilter.term = null"><i class="ui-grid-icon-cancel" ng-show="!!colFilter.term">&nbsp;</i>
            <!-- use !! because angular interprets 'f' as false -->
        </div>
    </div>
</div>

So the key in the template above is: <select class="ui-grid-filter-input" ng-model="colFilter.term" ng-options="status for status in getExternalScopes().status" ng-click="$event.stopPropagation()"></select>. In my example, getExternalScopes().status is the basis of the dropdown used for filtering the data.

Here's what the result looks like: git-contribute

@wendeldw, I hope this helps you. @PaulL1 this might help you in your decision on how to deal with this issue.

igwejk avatar Mar 06 '15 08:03 igwejk

@igwejk NIce, exept that in the new version getExternalScopes has been replaced by appScope (grid.appScope) http://ui-grid.info/docs/#/tutorial/305_appScope

bleuscyther avatar Mar 13 '15 04:03 bleuscyther

Dropdowns have been provided for filters, and also there is the ability to create custom filter directives with widgets of your choosing. Closing.

PaulL1 avatar May 27 '15 07:05 PaulL1