@ag-grid-enterprise/set-filter
Advanced tools
Comparing version 23.0.2 to 23.1.0
@@ -1,2 +0,2 @@ | ||
export { SetFilterModule } from "./setFilterModule"; | ||
export { SetFilter } from "./setFilter/setFilter"; | ||
export { SetFilterModule } from './setFilterModule'; | ||
export { SetFilter } from './setFilter/setFilter'; |
@@ -1,8 +0,7 @@ | ||
import { IDoesFilterPassParams, ISetFilterParams, ProvidedFilter } from "@ag-grid-community/core"; | ||
import { SetValueModel } from "./setValueModel"; | ||
import { SetFilterModel } from "./setFilterModel"; | ||
import { IDoesFilterPassParams, ISetFilterParams, ProvidedFilter, IAfterGuiAttachedParams } from '@ag-grid-community/core'; | ||
import { SetValueModel } from './setValueModel'; | ||
import { SetFilterModel } from './setFilterModel'; | ||
export declare class SetFilter extends ProvidedFilter { | ||
private valueModel; | ||
private eSelectAll; | ||
private eSelectAllContainer; | ||
private eMiniFilter; | ||
@@ -12,6 +11,6 @@ private eFilterLoading; | ||
private eventService; | ||
private selectAllState; | ||
private selectAllState?; | ||
private setFilterParams; | ||
private virtualList; | ||
private appliedModelValuesMapped; | ||
private appliedModelValues; | ||
protected updateUiVisibility(): void; | ||
@@ -27,10 +26,13 @@ protected createBodyTemplate(): string; | ||
private checkSetFilterDeprecatedParams; | ||
private addEventListenersForDataChanges; | ||
/** Called when the data in the grid changes, to prompt the set filter values to be updated. */ | ||
private syncValuesAfterDataChange; | ||
private setupSyncValuesAfterDataChange; | ||
private updateCheckboxIcon; | ||
setLoading(loading: boolean): void; | ||
private initialiseFilterBodyUi; | ||
private initVirtualList; | ||
private createSetListItem; | ||
afterGuiAttached(params: any): void; | ||
refreshVirtualList(): void; | ||
private initMiniFilter; | ||
private initSelectAll; | ||
afterGuiAttached(params: IAfterGuiAttachedParams): void; | ||
applyModel(): boolean; | ||
@@ -47,6 +49,5 @@ doesFilterPass(params: IDoesFilterPassParams): boolean; | ||
*/ | ||
setFilterValues(options: string[], selectAll?: boolean, notify?: boolean, toSelect?: string[]): void; | ||
setFilterValues(options: string[]): void; | ||
/** | ||
* Public method provided so the user can reset the values of the filter once that it has started | ||
* @param options The options to use. | ||
* Public method provided so the user can reset the values of the filter once that it has started. | ||
*/ | ||
@@ -57,14 +58,13 @@ resetFilterValues(): void; | ||
private onMiniFilterKeyPress; | ||
private onEnterKeyOnMiniFilter; | ||
private onMiniFilterInput; | ||
private onSelectAll; | ||
private doSelectAll; | ||
private onItemSelected; | ||
setMiniFilter(newMiniFilter: any): void; | ||
setMiniFilter(newMiniFilter: string): void; | ||
getMiniFilter(): string; | ||
selectEverything(): void; | ||
selectNothing(): void; | ||
unselectValue(value: any): void; | ||
selectValue(value: any): void; | ||
isValueSelected(value: any): boolean; | ||
unselectValue(value: string): void; | ||
selectValue(value: string): void; | ||
private refresh; | ||
isValueSelected(value: string): boolean; | ||
isEverythingSelected(): boolean; | ||
@@ -74,2 +74,3 @@ isNothingSelected(): boolean; | ||
getUniqueValue(index: any): string; | ||
refreshVirtualList(): void; | ||
} |
@@ -28,5 +28,10 @@ "use strict"; | ||
function SetFilter() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
// To make the filtering super fast, we store the values in an object, and check for the boolean value. | ||
// Although Set would be a more natural choice of data structure, its performance across browsers is | ||
// significantly worse than using an object: https://jsbench.me/hdk91jbw1h/ | ||
_this.appliedModelValues = null; | ||
return _this; | ||
} | ||
// unlike the simple filter's, nothing in the set filter UI shows/hides. | ||
// unlike the simple filters, nothing in the set filter UI shows/hides. | ||
// maybe this method belongs in abstractSimpleFilter??? | ||
@@ -36,3 +41,3 @@ SetFilter.prototype.updateUiVisibility = function () { }; | ||
var translate = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
return "<div ref=\"eFilterLoading\" class=\"ag-filter-loading ag-hidden\">" + translate('loadingOoo', 'Loading...') + "</div>\n <div>\n <div class=\"ag-filter-header-container\" role=\"presentation\">\n <ag-input-text-field class=\"ag-mini-filter\" ref=\"eMiniFilter\"></ag-input-text-field>\n <label ref=\"eSelectAllContainer\" class=\"ag-set-filter-item ag-set-filter-select-all\">\n <ag-checkbox ref=\"eSelectAll\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox><span class=\"ag-set-filter-item-value\">(" + translate('selectAll', 'Select All') + ")</span>\n </label>\n </div>\n <div ref=\"eSetFilterList\" class=\"ag-set-filter-list\" role=\"presentation\"></div>\n </div>"; | ||
return /* html */ "\n <div ref=\"eFilterLoading\" class=\"ag-filter-loading ag-hidden\">" + translate('loadingOoo', 'Loading...') + "</div>\n <div>\n <div class=\"ag-filter-header-container\" role=\"presentation\">\n <ag-input-text-field class=\"ag-mini-filter\" ref=\"eMiniFilter\"></ag-input-text-field>\n <label ref=\"eSelectAllContainer\" class=\"ag-set-filter-item ag-set-filter-select-all\">\n <ag-checkbox ref=\"eSelectAll\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox><span class=\"ag-set-filter-item-value\">(" + translate('selectAll', 'Select All') + ")</span>\n </label>\n </div>\n <div ref=\"eSetFilterList\" class=\"ag-set-filter-list\" role=\"presentation\"></div>\n </div>"; | ||
}; | ||
@@ -44,3 +49,2 @@ SetFilter.prototype.getCssIdentifier = function () { | ||
this.setMiniFilter(null); | ||
this.valueModel.setModel(null, true); | ||
this.selectEverything(); | ||
@@ -60,6 +64,5 @@ }; | ||
// also supporting old filter model for backwards compatibility | ||
var newValues = (model instanceof Array) ? model : model.values; | ||
var newValues = model instanceof Array ? model : model.values; | ||
this.valueModel.setModel(newValues); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.refresh(); | ||
}; | ||
@@ -82,35 +85,20 @@ SetFilter.prototype.getModelFromUi = function () { | ||
// both are missing | ||
if (!a && !b) { | ||
if (a == null && b == null) { | ||
return true; | ||
} | ||
// one is missing, other present | ||
if ((!a && b) || (a && !b)) { | ||
return false; | ||
} | ||
// both present, so compare | ||
// if different sizes, they are different | ||
if (a.values.length != b.values.length) { | ||
return false; | ||
} | ||
// now check each one value by value | ||
for (var i = 0; i < a.values.length; i++) { | ||
if (a.values[i] !== b.values[i]) { | ||
return false; | ||
} | ||
} | ||
// got this far means value lists are identical | ||
return true; | ||
return a != null && b != null && core_1._.areEqual(a.values, b.values); | ||
}; | ||
SetFilter.prototype.setParams = function (params) { | ||
var _this = this; | ||
_super.prototype.setParams.call(this, params); | ||
this.checkSetFilterDeprecatedParams(params); | ||
this.setFilterParams = params; | ||
this.valueModel = new setValueModel_1.SetValueModel(params.colDef, params.rowModel, params.valueGetter, params.doesRowPassOtherFilter, params.suppressSorting, function (loading) { return _this.setLoading(loading); }, this.valueFormatterService, params.column); | ||
this.initialiseFilterBodyUi(); | ||
var syncValuesAfterDataChange = !params.suppressSyncValuesAfterDataChange && | ||
// sync values only with CSRM | ||
this.rowModel.getType() === core_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE && | ||
// sync only needed if user not providing values | ||
!params.values; | ||
this.valueModel.onFilterValuesReady(function () { return _this.refresh(); }); | ||
var syncValuesAfterDataChange = this.rowModel.getType() === core_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE && | ||
!params.values && | ||
!params.suppressSyncValuesAfterDataChange; | ||
if (syncValuesAfterDataChange) { | ||
this.setupSyncValuesAfterDataChange(); | ||
this.addEventListenersForDataChanges(); | ||
} | ||
@@ -130,18 +118,16 @@ }; | ||
} | ||
if (params.suppressSyncValuesAfterDataChange) { | ||
var message_4 = 'ag-Grid: since version 23.1, the Set Filter param suppressSyncValuesAfterDataChange has' + | ||
' been deprecated and will be removed in a future major release.'; | ||
core_1._.doOnce(function () { return console.warn(message_4); }, 'suppressSyncValuesAfterDataChange deprecated'); | ||
} | ||
if (params.suppressRemoveEntries) { | ||
var message_5 = 'ag-Grid: since version 23.1, the Set Filter param suppressRemoveEntries has' + | ||
' been deprecated and will be removed in a future major release.'; | ||
core_1._.doOnce(function () { return console.warn(message_5); }, 'suppressRemoveEntries deprecated'); | ||
} | ||
}; | ||
// gets called with change to data values, thus need to update the values available for selection | ||
// in the set filter. | ||
SetFilter.prototype.syncValuesAfterDataChange = function () { | ||
var everythingSelected = !this.getModel(); | ||
this.valueModel.refreshAfterNewRowsLoaded(true, everythingSelected); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.onBtApply(false, true); | ||
}; | ||
// this keeps the filter up to date with changes in the row data | ||
SetFilter.prototype.setupSyncValuesAfterDataChange = function () { | ||
SetFilter.prototype.addEventListenersForDataChanges = function () { | ||
var _this = this; | ||
// add listener for when data is changed via transaction update (includes delta row mode | ||
// as this uses transaction updates) | ||
this.addDestroyableEventListener(this.eventService, core_1.Events.EVENT_ROW_DATA_UPDATED, this.syncValuesAfterDataChange.bind(this)); | ||
this.addDestroyableEventListener(this.eventService, core_1.Events.EVENT_ROW_DATA_UPDATED, function () { return _this.syncValuesAfterDataChange(); }); | ||
this.addDestroyableEventListener(this.eventService, core_1.Events.EVENT_CELL_VALUE_CHANGED, function (event) { | ||
@@ -155,2 +141,9 @@ // only interested in changes to do with this column | ||
}; | ||
/** Called when the data in the grid changes, to prompt the set filter values to be updated. */ | ||
SetFilter.prototype.syncValuesAfterDataChange = function (keepSelection) { | ||
if (keepSelection === void 0) { keepSelection = true; } | ||
this.valueModel.refetchValues(keepSelection); | ||
this.refresh(); | ||
this.onBtApply(false, true); | ||
}; | ||
SetFilter.prototype.updateCheckboxIcon = function () { | ||
@@ -163,25 +156,46 @@ this.eSelectAll.setValue(this.selectAllState); | ||
SetFilter.prototype.initialiseFilterBodyUi = function () { | ||
this.initVirtualList(); | ||
this.initMiniFilter(); | ||
this.initSelectAll(); | ||
}; | ||
SetFilter.prototype.initVirtualList = function () { | ||
var _this = this; | ||
this.virtualList = new core_1.VirtualList('filter'); | ||
this.getContext().wireBean(this.virtualList); | ||
var virtualList = this.virtualList = this.wireBean(new core_1.VirtualList('filter')); | ||
var eSetFilterList = this.getRefElement('eSetFilterList'); | ||
if (eSetFilterList) { | ||
eSetFilterList.appendChild(this.virtualList.getGui()); | ||
eSetFilterList.appendChild(virtualList.getGui()); | ||
} | ||
if (core_1._.exists(this.setFilterParams.cellHeight)) { | ||
this.virtualList.setRowHeight(this.setFilterParams.cellHeight); | ||
var cellHeight = this.setFilterParams.cellHeight; | ||
if (cellHeight != null) { | ||
virtualList.setRowHeight(cellHeight); | ||
} | ||
this.virtualList.setComponentCreator(this.createSetListItem.bind(this)); | ||
this.valueModel = new setValueModel_1.SetValueModel(this.setFilterParams.colDef, this.setFilterParams.rowModel, this.setFilterParams.valueGetter, this.setFilterParams.doesRowPassOtherFilter, this.setFilterParams.suppressSorting, function (values, toSelect) { return _this.setFilterValues(values, toSelect ? false : true, toSelect ? true : false, toSelect); }, this.setLoading.bind(this), this.valueFormatterService, this.setFilterParams.column); | ||
this.virtualList.setModel(new ModelWrapper(this.valueModel)); | ||
core_1._.setDisplayed(this.eMiniFilter.getGui(), !this.setFilterParams.suppressMiniFilter); | ||
this.eMiniFilter.setValue(this.valueModel.getMiniFilter()); | ||
this.eMiniFilter.onValueChange(function () { return _this.onMiniFilterInput(); }); | ||
this.addDestroyableEventListener(this.eMiniFilter.getInputElement(), 'keypress', this.onMiniFilterKeyPress.bind(this)); | ||
virtualList.setComponentCreator(function (value) { return _this.createSetListItem(value); }); | ||
virtualList.setModel(new ModelWrapper(this.valueModel)); | ||
}; | ||
SetFilter.prototype.createSetListItem = function (value) { | ||
var _this = this; | ||
var listItem = this.wireBean(new setFilterListItem_1.SetFilterListItem(value, this.setFilterParams)); | ||
var selected = this.valueModel.isValueSelected(value); | ||
listItem.setSelected(selected); | ||
listItem.addEventListener(setFilterListItem_1.SetFilterListItem.EVENT_SELECTED, function () { return _this.onItemSelected(value, listItem.isSelected()); }); | ||
return listItem; | ||
}; | ||
SetFilter.prototype.initMiniFilter = function () { | ||
var _this = this; | ||
var eMiniFilter = this.eMiniFilter; | ||
core_1._.setDisplayed(eMiniFilter.getGui(), !this.setFilterParams.suppressMiniFilter); | ||
eMiniFilter.setValue(this.valueModel.getMiniFilter()); | ||
eMiniFilter.onValueChange(function () { return _this.onMiniFilterInput(); }); | ||
this.addDestroyableEventListener(eMiniFilter.getInputElement(), 'keypress', function (e) { return _this.onMiniFilterKeyPress(e); }); | ||
}; | ||
SetFilter.prototype.initSelectAll = function () { | ||
var _this = this; | ||
this.updateCheckboxIcon(); | ||
this.addDestroyableEventListener(this.eSelectAllContainer, 'click', this.onSelectAll.bind(this)); | ||
this.updateSelectAll(); | ||
var eSelectAllContainer = this.getRefElement('eSelectAllContainer'); | ||
if (this.setFilterParams.suppressSelectAll) { | ||
core_1._.setDisplayed(this.eSelectAllContainer, false); | ||
core_1._.setDisplayed(eSelectAllContainer, false); | ||
} | ||
else { | ||
this.addDestroyableEventListener(eSelectAllContainer, 'click', function (e) { return _this.onSelectAll(e); }); | ||
} | ||
this.addDestroyableEventListener(this.eSelectAll.getInputElement(), 'keydown', function (e) { | ||
@@ -193,18 +207,7 @@ if (e.keyCode === core_1.Constants.KEY_SPACE) { | ||
}); | ||
this.virtualList.refresh(); | ||
}; | ||
SetFilter.prototype.createSetListItem = function (value) { | ||
var _this = this; | ||
var listItem = new setFilterListItem_1.SetFilterListItem(value, this.setFilterParams.column); | ||
this.getContext().wireBean(listItem); | ||
var selected = this.valueModel.isValueSelected(value); | ||
listItem.setSelected(selected); | ||
listItem.addEventListener(setFilterListItem_1.SetFilterListItem.EVENT_SELECTED, function () { | ||
_this.onItemSelected(value, listItem.isSelected()); | ||
}); | ||
return listItem; | ||
}; | ||
// we need to have the gui attached before we can draw the virtual rows, as the | ||
// virtual row logic needs info about the gui state | ||
// we need to have the GUI attached before we can draw the virtual rows, as the | ||
// virtual row logic needs info about the GUI state | ||
SetFilter.prototype.afterGuiAttached = function (params) { | ||
_super.prototype.afterGuiAttached.call(this, params); | ||
var _a = this, virtualList = _a.virtualList, eMiniFilter = _a.eMiniFilter; | ||
@@ -216,43 +219,37 @@ var translate = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
}; | ||
SetFilter.prototype.refreshVirtualList = function () { | ||
this.virtualList.refresh(); | ||
}; | ||
SetFilter.prototype.applyModel = function () { | ||
var _this = this; | ||
var res = _super.prototype.applyModel.call(this); | ||
var result = _super.prototype.applyModel.call(this); | ||
// keep the appliedModelValuesMapped in sync with the applied model | ||
var appliedModel = this.getModel(); | ||
if (appliedModel) { | ||
this.appliedModelValuesMapped = {}; | ||
appliedModel.values.forEach(function (value) { return _this.appliedModelValuesMapped[value] = true; }); | ||
this.appliedModelValues = {}; | ||
core_1._.forEach(appliedModel.values, function (value) { return _this.appliedModelValues[value] = true; }); | ||
} | ||
else { | ||
this.appliedModelValuesMapped = undefined; | ||
this.appliedModelValues = null; | ||
} | ||
return res; | ||
return result; | ||
}; | ||
SetFilter.prototype.doesFilterPass = function (params) { | ||
// should never happen, if filter model not set, then this method should never be called | ||
if (!this.appliedModelValuesMapped) { | ||
var _this = this; | ||
if (this.appliedModelValues == null) { | ||
return true; | ||
} | ||
var value = this.setFilterParams.valueGetter(params.node); | ||
if (this.setFilterParams.colDef.keyCreator) { | ||
value = this.setFilterParams.colDef.keyCreator({ value: value }); | ||
var _a = this.setFilterParams, valueGetter = _a.valueGetter, keyCreator = _a.colDef.keyCreator; | ||
var value = valueGetter(params.node); | ||
if (keyCreator) { | ||
value = keyCreator({ value: value }); | ||
} | ||
value = core_1._.makeNull(value); | ||
if (Array.isArray(value)) { | ||
for (var i = 0; i < value.length; i++) { | ||
var valueExistsInMap = !!this.appliedModelValuesMapped[value[i]]; | ||
if (valueExistsInMap) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return core_1._.some(value, function (v) { return _this.appliedModelValues[core_1._.makeNull(v)] === true; }); | ||
} | ||
return !!this.appliedModelValuesMapped[value]; | ||
// Comparing against a value performs better than just checking for undefined | ||
// https://jsbench.me/hdk91jbw1h/ | ||
return this.appliedModelValues[value] === true; | ||
}; | ||
SetFilter.prototype.onNewRowsLoaded = function () { | ||
var valuesType = this.valueModel.getValuesType(); | ||
var valuesTypeProvided = valuesType === setValueModel_1.SetFilterModelValuesType.PROVIDED_CB || | ||
var valuesTypeProvided = valuesType === setValueModel_1.SetFilterModelValuesType.PROVIDED_CALLBACK || | ||
valuesType === setValueModel_1.SetFilterModelValuesType.PROVIDED_LIST; | ||
@@ -265,8 +262,3 @@ // if the user is providing values, and we are keeping the previous selection, then | ||
} | ||
var everythingSelected = !this.getModel(); | ||
// default is reset | ||
this.valueModel.refreshAfterNewRowsLoaded(keepSelection, everythingSelected); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.onBtApply(false, true); | ||
this.syncValuesAfterDataChange(keepSelection); | ||
}; | ||
@@ -282,17 +274,8 @@ //noinspection JSUnusedGlobalSymbols | ||
*/ | ||
SetFilter.prototype.setFilterValues = function (options, selectAll, notify, toSelect) { | ||
SetFilter.prototype.setFilterValues = function (options) { | ||
var _this = this; | ||
if (selectAll === void 0) { selectAll = false; } | ||
if (notify === void 0) { notify = true; } | ||
this.valueModel.overrideValues(options, this.isNewRowsActionKeep()); | ||
this.valueModel.onFilterValuesReady(function () { | ||
var keepSelection = _this.setFilterParams && _this.setFilterParams.newRowsAction === 'keep'; | ||
_this.valueModel.setValuesType(setValueModel_1.SetFilterModelValuesType.PROVIDED_LIST); | ||
_this.valueModel.refreshValues(options, keepSelection, selectAll); | ||
_this.updateSelectAll(); | ||
var actualToSelect = toSelect ? toSelect : options; | ||
actualToSelect.forEach(function (option) { return _this.valueModel.selectValue(option); }); | ||
_this.virtualList.refresh(); | ||
if (notify) { | ||
_this.onUiChanged(); | ||
} | ||
_this.refresh(); | ||
_this.onUiChanged(); | ||
}); | ||
@@ -302,7 +285,6 @@ }; | ||
/** | ||
* Public method provided so the user can reset the values of the filter once that it has started | ||
* @param options The options to use. | ||
* Public method provided so the user can reset the values of the filter once that it has started. | ||
*/ | ||
SetFilter.prototype.resetFilterValues = function () { | ||
this.valueModel.setValuesType(setValueModel_1.SetFilterModelValuesType.NOT_PROVIDED); | ||
this.valueModel.setValuesType(setValueModel_1.SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES); | ||
this.onNewRowsLoaded(); | ||
@@ -328,14 +310,9 @@ }; | ||
if (core_1._.isKeyPressed(e, core_1.Constants.KEY_ENTER)) { | ||
this.onEnterKeyOnMiniFilter(); | ||
this.valueModel.selectAll(true); | ||
this.refresh(); | ||
this.onUiChanged(true); | ||
} | ||
}; | ||
SetFilter.prototype.onEnterKeyOnMiniFilter = function () { | ||
this.valueModel.selectAllFromMiniFilter(); | ||
this.virtualList.refresh(); | ||
this.updateSelectAll(); | ||
this.onUiChanged(true); | ||
}; | ||
SetFilter.prototype.onMiniFilterInput = function () { | ||
var miniFilterChanged = this.valueModel.setMiniFilter(this.eMiniFilter.getValue()); | ||
if (miniFilterChanged) { | ||
if (this.valueModel.setMiniFilter(this.eMiniFilter.getValue())) { | ||
this.virtualList.refresh(); | ||
@@ -348,21 +325,11 @@ } | ||
core_1._.addAgGridEventPath(event); | ||
if (this.selectAllState === true) { | ||
this.selectAllState = false; | ||
this.selectAllState = !this.selectAllState; | ||
if (this.selectAllState) { | ||
this.valueModel.selectAll(); | ||
} | ||
else { | ||
this.selectAllState = true; | ||
this.valueModel.selectNothing(); | ||
} | ||
this.doSelectAll(); | ||
}; | ||
SetFilter.prototype.doSelectAll = function () { | ||
var checked = this.selectAllState === true; | ||
if (checked) { | ||
this.valueModel.selectAllUsingMiniFilter(); | ||
} | ||
else { | ||
this.valueModel.selectNothingUsingMiniFilter(); | ||
} | ||
this.virtualList.refresh(); | ||
this.refresh(); | ||
this.onUiChanged(); | ||
this.updateSelectAll(); | ||
}; | ||
@@ -374,3 +341,3 @@ SetFilter.prototype.onItemSelected = function (value, selected) { | ||
else { | ||
this.valueModel.unselectValue(value); | ||
this.valueModel.deselectValue(value); | ||
} | ||
@@ -388,20 +355,20 @@ this.updateSelectAll(); | ||
SetFilter.prototype.selectEverything = function () { | ||
this.valueModel.selectAllUsingMiniFilter(); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.valueModel.selectAll(); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.selectNothing = function () { | ||
this.valueModel.selectNothingUsingMiniFilter(); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.valueModel.selectNothing(); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.unselectValue = function (value) { | ||
this.valueModel.unselectValue(value); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.valueModel.deselectValue(value); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.selectValue = function (value) { | ||
this.valueModel.selectValue(value); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.refresh = function () { | ||
this.virtualList.refresh(); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
}; | ||
@@ -423,2 +390,5 @@ SetFilter.prototype.isValueSelected = function (value) { | ||
}; | ||
SetFilter.prototype.refreshVirtualList = function () { | ||
this.virtualList.refresh(); | ||
}; | ||
__decorate([ | ||
@@ -428,5 +398,2 @@ core_1.RefSelector('eSelectAll') | ||
__decorate([ | ||
core_1.RefSelector('eSelectAllContainer') | ||
], SetFilter.prototype, "eSelectAllContainer", void 0); | ||
__decorate([ | ||
core_1.RefSelector('eMiniFilter') | ||
@@ -433,0 +400,0 @@ ], SetFilter.prototype, "eMiniFilter", void 0); |
@@ -1,5 +0,7 @@ | ||
import { AgEvent, Column, Component } from "@ag-grid-community/core"; | ||
import { AgEvent, ColDef, Component, ISetFilterParams } from '@ag-grid-community/core'; | ||
export interface SelectedEvent extends AgEvent { | ||
} | ||
export declare class SetFilterListItem extends Component { | ||
private readonly value; | ||
private readonly params; | ||
static EVENT_SELECTED: string; | ||
@@ -9,9 +11,8 @@ private gridOptionsWrapper; | ||
private userComponentFactory; | ||
private eFilterItemValue; | ||
private static TEMPLATE; | ||
private eCheckbox; | ||
private selected; | ||
private value; | ||
private column; | ||
constructor(value: any, column: Column); | ||
private useCellRenderer; | ||
private tooltipText; | ||
constructor(value: any, params: ISetFilterParams); | ||
private init; | ||
@@ -22,3 +23,6 @@ isSelected(): boolean; | ||
render(): void; | ||
private getFilterValueFormatter; | ||
private getFormattedValue; | ||
private renderCell; | ||
getComponentHolder(): ColDef; | ||
getTooltipText(): string; | ||
} |
@@ -25,25 +25,9 @@ "use strict"; | ||
__extends(SetFilterListItem, _super); | ||
function SetFilterListItem(value, column) { | ||
function SetFilterListItem(value, params) { | ||
var _this = _super.call(this, SetFilterListItem.TEMPLATE) || this; | ||
_this.value = value; | ||
_this.params = params; | ||
_this.selected = true; | ||
_this.value = value; | ||
_this.column = column; | ||
return _this; | ||
} | ||
SetFilterListItem.prototype.useCellRenderer = function (target, eTarget, params) { | ||
var cellRendererPromise = this.userComponentFactory.newCellRenderer(target.filterParams, params); | ||
if (cellRendererPromise != null) { | ||
core_1._.bindCellRendererToHtmlElement(cellRendererPromise, eTarget); | ||
} | ||
else { | ||
if (params.valueFormatted == null && params.value == null) { | ||
var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
eTarget.innerText = '(' + localeTextFunc('blanks', 'Blanks') + ')'; | ||
} | ||
else { | ||
eTarget.innerText = params.valueFormatted != null ? params.valueFormatted : params.value; | ||
} | ||
} | ||
return cellRendererPromise; | ||
}; | ||
SetFilterListItem.prototype.init = function () { | ||
@@ -71,17 +55,44 @@ var _this = this; | ||
SetFilterListItem.prototype.render = function () { | ||
var _this = this; | ||
var valueElement = this.queryForHtmlElement('.ag-set-filter-item-value'); | ||
var colDef = this.column.getColDef(); | ||
var filterValueFormatter = this.getFilterValueFormatter(colDef); | ||
var valueFormatted = this.valueFormatterService.formatValue(this.column, null, null, this.value, filterValueFormatter); | ||
var _a = this, value = _a.value, _b = _a.params, column = _b.column, colDef = _b.colDef; | ||
var formattedValue = this.getFormattedValue(colDef, column, value); | ||
if (this.params.showTooltips) { | ||
this.tooltipText = core_1._.escape(formattedValue != null ? formattedValue : value); | ||
if (core_1._.exists(this.tooltipText)) { | ||
if (this.gridOptionsWrapper.isEnableBrowserTooltips()) { | ||
this.eFilterItemValue.title = this.tooltipText; | ||
} | ||
else { | ||
this.addFeature(new core_1.TooltipFeature(this, 'setFilterValue')); | ||
} | ||
} | ||
} | ||
var params = { | ||
value: this.value, | ||
valueFormatted: valueFormatted, | ||
value: value, | ||
valueFormatted: formattedValue, | ||
api: this.gridOptionsWrapper.getApi() | ||
}; | ||
var componentPromise = this.useCellRenderer(colDef, valueElement, params); | ||
if (!componentPromise) { | ||
this.renderCell(colDef, this.eFilterItemValue, params); | ||
}; | ||
SetFilterListItem.prototype.getFormattedValue = function (colDef, column, value) { | ||
var filterParams = colDef.filterParams; | ||
var formatter = filterParams == null ? null : filterParams.valueFormatter; | ||
return this.valueFormatterService.formatValue(column, null, null, value, formatter, false); | ||
}; | ||
SetFilterListItem.prototype.renderCell = function (target, eTarget, params) { | ||
var _this = this; | ||
var filterParams = target.filterParams; | ||
var cellRendererPromise = this.userComponentFactory.newSetFilterCellRenderer(filterParams, params); | ||
if (cellRendererPromise == null) { | ||
var valueToRender = params.valueFormatted == null ? params.value : params.valueFormatted; | ||
if (valueToRender == null) { | ||
var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
eTarget.innerText = "(" + localeTextFunc('blanks', 'Blanks') + ")"; | ||
} | ||
else { | ||
eTarget.innerText = valueToRender; | ||
} | ||
return; | ||
} | ||
componentPromise.then(function (component) { | ||
core_1._.bindCellRendererToHtmlElement(cellRendererPromise, eTarget); | ||
cellRendererPromise.then(function (component) { | ||
if (component && component.destroy) { | ||
@@ -92,7 +103,10 @@ _this.addDestroyFunc(component.destroy.bind(component)); | ||
}; | ||
SetFilterListItem.prototype.getFilterValueFormatter = function (colDef) { | ||
return colDef.filterParams ? colDef.filterParams.valueFormatter : undefined; | ||
SetFilterListItem.prototype.getComponentHolder = function () { | ||
return this.params.column.getColDef(); | ||
}; | ||
SetFilterListItem.prototype.getTooltipText = function () { | ||
return this.tooltipText; | ||
}; | ||
SetFilterListItem.EVENT_SELECTED = 'selected'; | ||
SetFilterListItem.TEMPLATE = "<label class=\"ag-set-filter-item\">\n <ag-checkbox ref=\"eCheckbox\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox>\n <span class=\"ag-set-filter-item-value\"></span>\n </label>"; | ||
SetFilterListItem.TEMPLATE = "\n <label class=\"ag-set-filter-item\">\n <ag-checkbox ref=\"eCheckbox\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox>\n <span ref=\"eFilterItemValue\" class=\"ag-set-filter-item-value\"></span>\n </label>"; | ||
__decorate([ | ||
@@ -108,2 +122,5 @@ core_1.Autowired('gridOptionsWrapper') | ||
__decorate([ | ||
core_1.RefSelector('eFilterItemValue') | ||
], SetFilterListItem.prototype, "eFilterItemValue", void 0); | ||
__decorate([ | ||
core_1.RefSelector('eCheckbox') | ||
@@ -110,0 +127,0 @@ ], SetFilterListItem.prototype, "eCheckbox", void 0); |
@@ -1,4 +0,4 @@ | ||
import { ProvidedFilterModel } from "@ag-grid-community/core"; | ||
import { ProvidedFilterModel } from '@ag-grid-community/core'; | ||
export interface SetFilterModel extends ProvidedFilterModel { | ||
values: string[]; | ||
} |
@@ -1,3 +0,3 @@ | ||
import { FilterChangedEvent, Component, IFloatingFilter, IFloatingFilterParams } from "@ag-grid-community/core"; | ||
import { SetFilterModel } from "./setFilterModel"; | ||
import { FilterChangedEvent, Component, IFloatingFilter, IFloatingFilterParams } from '@ag-grid-community/core'; | ||
import { SetFilterModel } from './setFilterModel'; | ||
export declare class SetFloatingFilterComp extends Component implements IFloatingFilter { | ||
@@ -4,0 +4,0 @@ private eFloatingFilterText; |
@@ -27,3 +27,3 @@ "use strict"; | ||
function SetFloatingFilterComp() { | ||
var _this = _super.call(this, "<div class=\"ag-floating-filter-input\" role=\"presentation\"><ag-input-text-field ref=\"eFloatingFilterText\"></ag-input-text-field></div>") || this; | ||
var _this = _super.call(this, /* html */ "\n <div class=\"ag-floating-filter-input\" role=\"presentation\">\n <ag-input-text-field ref=\"eFloatingFilterText\"></ag-input-text-field>\n </div>") || this; | ||
_this.availableValuesListenerAdded = false; | ||
@@ -37,5 +37,5 @@ return _this; | ||
// unlike other filters, what we show in the floating filter can be different, even | ||
// if another filter changes. this is due to how set filter restricts it's values based | ||
// on selections in other filters. eg if you filter Language to English, then the set filter | ||
// on Country will only show English speaking countries. thus the list of items to show | ||
// if another filter changes. this is due to how set filter restricts its values based | ||
// on selections in other filters, e.g. if you filter Language to English, then the set filter | ||
// on Country will only show English speaking countries. Thus the list of items to show | ||
// in the floating filter can change. | ||
@@ -53,3 +53,3 @@ SetFloatingFilterComp.prototype.onAvailableValuesChanged = function (filterChangedEvent) { | ||
var setValueModel = setFilter.getValueModel(); | ||
_this.addDestroyableEventListener(setValueModel, setValueModel_1.SetValueModel.EVENT_AVAILABLE_VALUES_CHANGES, _this.onAvailableValuesChanged.bind(_this)); | ||
_this.addDestroyableEventListener(setValueModel, setValueModel_1.SetValueModel.EVENT_AVAILABLE_VALUES_CHANGED, _this.onAvailableValuesChanged.bind(_this)); | ||
}); | ||
@@ -68,3 +68,3 @@ this.availableValuesListenerAdded = true; | ||
// also supporting old filter model for backwards compatibility | ||
var values = (this.lastKnownModel instanceof Array) ? this.lastKnownModel : this.lastKnownModel.values; | ||
var values = this.lastKnownModel instanceof Array ? this.lastKnownModel : this.lastKnownModel.values; | ||
if (!values || values.length === 0) { | ||
@@ -76,5 +76,5 @@ this.eFloatingFilterText.setValue(''); | ||
var valueModel = setFilter.getValueModel(); | ||
var availableValues = values.filter(valueModel.isValueAvailable.bind(valueModel)); | ||
var availableValues = core_1._.filter(values, function (v) { return valueModel.isValueAvailable(v); }); | ||
// format all the values, if a formatter is provided | ||
var formattedValues = availableValues.map(function (value) { | ||
var formattedValues = core_1._.map(availableValues, function (value) { | ||
var formattedValue = _this.valueFormatterService.formatValue(_this.params.column, null, null, value); | ||
@@ -84,3 +84,3 @@ return formattedValue != null ? formattedValue : value; | ||
var arrayToDisplay = formattedValues.length > 10 ? formattedValues.slice(0, 10).concat('...') : formattedValues; | ||
var valuesString = "(" + formattedValues.length + ") " + arrayToDisplay.join(","); | ||
var valuesString = "(" + formattedValues.length + ") " + arrayToDisplay.join(','); | ||
_this.eFloatingFilterText.setValue(valuesString); | ||
@@ -87,0 +87,0 @@ }); |
@@ -1,74 +0,77 @@ | ||
import { ColDef, Column, IRowModel, ValueFormatterService, IEventEmitter } from "@ag-grid-community/core"; | ||
import { ColDef, Column, IRowModel, ValueFormatterService, IEventEmitter, RowNode } from '@ag-grid-community/core'; | ||
export declare enum SetFilterModelValuesType { | ||
PROVIDED_LIST = 0, | ||
PROVIDED_CB = 1, | ||
NOT_PROVIDED = 2 | ||
PROVIDED_CALLBACK = 1, | ||
TAKEN_FROM_GRID_VALUES = 2 | ||
} | ||
export declare class SetValueModel implements IEventEmitter { | ||
static EVENT_AVAILABLE_VALUES_CHANGES: string; | ||
private colDef; | ||
private filterParams; | ||
private clientSideRowModel; | ||
private valueGetter; | ||
private allUniqueValues; | ||
private availableUniqueValues; | ||
private availableUniqueValuesMap; | ||
private readonly colDef; | ||
private readonly valueGetter; | ||
private readonly doesRowPassOtherFilters; | ||
private readonly suppressSorting; | ||
private readonly setIsLoading; | ||
private readonly valueFormatterService; | ||
private readonly column; | ||
static EVENT_AVAILABLE_VALUES_CHANGED: string; | ||
private readonly localEventService; | ||
private readonly filterParams; | ||
private readonly clientSideRowModel; | ||
private readonly formatter; | ||
private valuesType; | ||
private miniFilterText; | ||
/** Values provided to the filter for use. */ | ||
private providedValues; | ||
/** Values can be loaded asynchronously, so wait on this promise if you need to ensure values have been loaded. */ | ||
private allValuesPromise; | ||
/** All possible values for the filter, sorted if required. */ | ||
private allValues; | ||
/** Remaining values when filters from other columns have been applied. */ | ||
private availableValues; | ||
/** All values that are currently displayed, after the mini-filter has been applied. */ | ||
private displayedValues; | ||
private miniFilter; | ||
private selectedValuesCount; | ||
private selectedValuesMap; | ||
private suppressSorting; | ||
private formatter; | ||
private showingAvailableOnly; | ||
private valuesType; | ||
private doesRowPassOtherFilters; | ||
private modelUpdatedFunc; | ||
private isLoadingFunc; | ||
private filterValuesExternalPromise; | ||
private filterValuesPromise; | ||
private valueFormatterService; | ||
private column; | ||
private localEventService; | ||
constructor(colDef: ColDef, rowModel: IRowModel, valueGetter: any, doesRowPassOtherFilters: any, suppressSorting: boolean, modelUpdatedFunc: (values: string[] | null, selected?: string[] | null) => void, isLoadingFunc: (loading: boolean) => void, valueFormatterService: ValueFormatterService, column: Column); | ||
/** Values that have been selected for this filter. */ | ||
private selectedValues; | ||
constructor(colDef: ColDef, rowModel: IRowModel, valueGetter: (node: RowNode) => any, doesRowPassOtherFilters: (node: RowNode) => boolean, suppressSorting: boolean, setIsLoading: (loading: boolean) => void, valueFormatterService: ValueFormatterService, column: Column); | ||
addEventListener(eventType: string, listener: Function, async?: boolean): void; | ||
removeEventListener(eventType: string, listener: Function, async?: boolean): void; | ||
refreshAfterNewRowsLoaded(keepSelection: any, everythingSelected: boolean): void; | ||
refreshValues(valuesToUse: string[], keepSelection: any, isSelectAll: boolean): void; | ||
private refreshSelection; | ||
/** | ||
* Re-fetches the values used in the filter from the value source. | ||
* If keepSelection is false or selectAll is true, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
refetchValues(keepSelection?: boolean): void; | ||
/** | ||
* Overrides the current values being used for the set filter. | ||
* If keepSelection is false, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
overrideValues(valuesToUse: string[], keepSelection?: boolean): void; | ||
refreshAfterAnyFilterChanged(): void; | ||
private createAllUniqueValues; | ||
private onAsyncValuesLoaded; | ||
private areValuesSync; | ||
private updateAllValues; | ||
setValuesType(value: SetFilterModelValuesType): void; | ||
getValuesType(): SetFilterModelValuesType; | ||
private setValues; | ||
private extractSyncValuesToUse; | ||
isValueAvailable(value: string): boolean; | ||
private createAvailableUniqueValues; | ||
private showAvailableOnly; | ||
private updateAvailableValues; | ||
private sortValues; | ||
private getUniqueValues; | ||
setMiniFilter(newMiniFilter: string | null): boolean; | ||
private getValuesFromRows; | ||
/** Sets mini filter value. Returns true if it changed from last value, otherwise false. */ | ||
setMiniFilter(value?: string): boolean; | ||
getMiniFilter(): string; | ||
private processMiniFilter; | ||
private updateDisplayedValues; | ||
getDisplayedValueCount(): number; | ||
getDisplayedValue(index: any): any; | ||
selectAllUsingMiniFilter(): void; | ||
private selectOn; | ||
private valueToKey; | ||
private keyToValue; | ||
getDisplayedValue(index: any): string; | ||
isFilterActive(): boolean; | ||
selectNothingUsingMiniFilter(): void; | ||
private selectNothing; | ||
getUniqueValueCount(): number; | ||
getUniqueValue(index: any): string | null; | ||
unselectValue(value: any): void; | ||
selectAllFromMiniFilter(): void; | ||
selectValue(value: any): void; | ||
isValueSelected(value: any): boolean; | ||
selectAll(clearExistingSelection?: boolean): void; | ||
selectNothing(): void; | ||
selectValue(value: string): void; | ||
deselectValue(value: string): void; | ||
isValueSelected(value: string): boolean; | ||
isEverythingSelected(): boolean; | ||
isNothingSelected(): boolean; | ||
getModel(): string[] | null; | ||
setModel(model: string[] | null, isSelectAll?: boolean): void; | ||
private setSyncModel; | ||
onFilterValuesReady(callback: () => void): void; | ||
setModel(model: string[]): void; | ||
onFilterValuesReady(callback: (values: string[]) => void): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("@ag-grid-community/core"); | ||
// we cannot have 'null' as a key in a JavaScript map, | ||
// it needs to be a string. so we use this string for | ||
// storing null values. | ||
var NULL_VALUE = '___NULL___'; | ||
var SetFilterModelValuesType; | ||
(function (SetFilterModelValuesType) { | ||
SetFilterModelValuesType[SetFilterModelValuesType["PROVIDED_LIST"] = 0] = "PROVIDED_LIST"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["PROVIDED_CB"] = 1] = "PROVIDED_CB"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["NOT_PROVIDED"] = 2] = "NOT_PROVIDED"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["PROVIDED_CALLBACK"] = 1] = "PROVIDED_CALLBACK"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["TAKEN_FROM_GRID_VALUES"] = 2] = "TAKEN_FROM_GRID_VALUES"; | ||
})(SetFilterModelValuesType = exports.SetFilterModelValuesType || (exports.SetFilterModelValuesType = {})); | ||
var SetValueModel = /** @class */ (function () { | ||
function SetValueModel(colDef, rowModel, valueGetter, doesRowPassOtherFilters, suppressSorting, modelUpdatedFunc, isLoadingFunc, valueFormatterService, column) { | ||
this.localEventService = new core_1.EventService(); | ||
this.suppressSorting = suppressSorting; | ||
function SetValueModel(colDef, rowModel, valueGetter, doesRowPassOtherFilters, suppressSorting, setIsLoading, valueFormatterService, column) { | ||
var _this = this; | ||
this.colDef = colDef; | ||
this.valueGetter = valueGetter; | ||
this.doesRowPassOtherFilters = doesRowPassOtherFilters; | ||
this.modelUpdatedFunc = modelUpdatedFunc; | ||
this.isLoadingFunc = isLoadingFunc; | ||
this.suppressSorting = suppressSorting; | ||
this.setIsLoading = setIsLoading; | ||
this.valueFormatterService = valueFormatterService; | ||
this.column = column; | ||
this.localEventService = new core_1.EventService(); | ||
this.miniFilterText = null; | ||
// The lookup for a set is much faster than the lookup for an array, especially when the length of the array is | ||
// thousands of records long, so where lookups are important we use a set. | ||
/** Values provided to the filter for use. */ | ||
this.providedValues = null; | ||
/** All possible values for the filter, sorted if required. */ | ||
this.allValues = []; | ||
/** Remaining values when filters from other columns have been applied. */ | ||
this.availableValues = new Set(); | ||
/** All values that are currently displayed, after the mini-filter has been applied. */ | ||
this.displayedValues = []; | ||
/** Values that have been selected for this filter. */ | ||
this.selectedValues = new Set(); | ||
if (rowModel.getType() === core_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE) { | ||
this.clientSideRowModel = rowModel; | ||
} | ||
this.filterParams = this.colDef.filterParams ? this.colDef.filterParams : {}; | ||
if (core_1._.exists(this.filterParams) && core_1._.exists(this.filterParams.values)) { | ||
this.valuesType = Array.isArray(this.filterParams.values) ? | ||
SetFilterModelValuesType.PROVIDED_LIST : | ||
SetFilterModelValuesType.PROVIDED_CB; | ||
this.showingAvailableOnly = this.filterParams.suppressRemoveEntries !== true; | ||
this.filterParams = this.colDef.filterParams || {}; | ||
this.formatter = this.filterParams.textFormatter || core_1.TextFilter.DEFAULT_FORMATTER; | ||
var values = this.filterParams.values; | ||
if (values == null) { | ||
this.valuesType = SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES; | ||
} | ||
else { | ||
this.valuesType = SetFilterModelValuesType.NOT_PROVIDED; | ||
this.showingAvailableOnly = true; | ||
this.valuesType = Array.isArray(values) ? | ||
SetFilterModelValuesType.PROVIDED_LIST : | ||
SetFilterModelValuesType.PROVIDED_CALLBACK; | ||
this.providedValues = values; | ||
} | ||
this.createAllUniqueValues(); | ||
this.createAvailableUniqueValues(); | ||
// by default, no filter, so we display everything | ||
this.displayedValues = this.availableUniqueValues; | ||
this.miniFilter = null; | ||
// we use a map rather than an array for the selected values as the lookup | ||
// for a map is much faster than the lookup for an array, especially when | ||
// the length of the array is thousands of records long | ||
this.selectNothing(); | ||
this.selectAllUsingMiniFilter(); | ||
this.formatter = this.filterParams.textFormatter ? this.filterParams.textFormatter : core_1.TextFilter.DEFAULT_FORMATTER; | ||
this.updateAllValues(); | ||
// start with everything selected | ||
this.allValuesPromise.then(function (values) { return _this.selectedValues = core_1._.convertToSet(values); }); | ||
} | ||
@@ -57,61 +59,72 @@ SetValueModel.prototype.addEventListener = function (eventType, listener, async) { | ||
}; | ||
// if keepSelection not set will always select all filters | ||
// if keepSelection set will keep current state of selected filters | ||
// unless selectAll chosen in which case will select all | ||
SetValueModel.prototype.refreshAfterNewRowsLoaded = function (keepSelection, everythingSelected) { | ||
this.createAllUniqueValues(); | ||
this.refreshSelection(keepSelection, everythingSelected); | ||
/** | ||
* Re-fetches the values used in the filter from the value source. | ||
* If keepSelection is false or selectAll is true, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
SetValueModel.prototype.refetchValues = function (keepSelection) { | ||
var _this = this; | ||
if (keepSelection === void 0) { keepSelection = true; } | ||
var currentModel = this.getModel(); | ||
this.updateAllValues(); | ||
// ensure model is updated for new values | ||
this.allValuesPromise.then(function () { return _this.setModel(keepSelection ? currentModel : null); }); | ||
}; | ||
// if keepSelection not set will always select all filters | ||
// if keepSelection set will keep current state of selected filters | ||
// unless selectAll chosen in which case will select all | ||
SetValueModel.prototype.refreshValues = function (valuesToUse, keepSelection, isSelectAll) { | ||
this.setValues(valuesToUse); | ||
this.refreshSelection(keepSelection, isSelectAll); | ||
/** | ||
* Overrides the current values being used for the set filter. | ||
* If keepSelection is false, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
SetValueModel.prototype.overrideValues = function (valuesToUse, keepSelection) { | ||
var _this = this; | ||
if (keepSelection === void 0) { keepSelection = true; } | ||
// wait for any existing values to be populated before overriding | ||
this.allValuesPromise.then(function () { | ||
_this.valuesType = SetFilterModelValuesType.PROVIDED_LIST; | ||
_this.providedValues = valuesToUse; | ||
_this.refetchValues(keepSelection); | ||
}); | ||
}; | ||
SetValueModel.prototype.refreshSelection = function (keepSelection, isSelectAll) { | ||
this.createAvailableUniqueValues(); | ||
var oldModel = Object.keys(this.selectedValuesMap); | ||
this.selectNothing(); | ||
this.processMiniFilter(); | ||
if (keepSelection) { | ||
this.setModel(oldModel, isSelectAll); | ||
} | ||
else { | ||
this.selectAllUsingMiniFilter(); | ||
} | ||
}; | ||
SetValueModel.prototype.refreshAfterAnyFilterChanged = function () { | ||
if (this.showingAvailableOnly) { | ||
this.createAvailableUniqueValues(); | ||
this.processMiniFilter(); | ||
if (this.showAvailableOnly()) { | ||
this.updateAvailableValues(); | ||
} | ||
}; | ||
SetValueModel.prototype.createAllUniqueValues = function () { | ||
if (this.areValuesSync()) { | ||
var valuesToUse = this.extractSyncValuesToUse(); | ||
this.setValues(valuesToUse); | ||
this.filterValuesPromise = core_1.Promise.resolve([]); | ||
SetValueModel.prototype.updateAllValues = function () { | ||
var _this = this; | ||
switch (this.valuesType) { | ||
case SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES: | ||
case SetFilterModelValuesType.PROVIDED_LIST: { | ||
var values = this.valuesType === SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES ? | ||
this.getValuesFromRows(false) : core_1._.toStrings(this.providedValues); | ||
var sortedValues = this.sortValues(values); | ||
this.allValues = sortedValues; | ||
this.allValuesPromise = core_1.Promise.resolve(sortedValues); | ||
break; | ||
} | ||
case SetFilterModelValuesType.PROVIDED_CALLBACK: { | ||
this.setIsLoading(true); | ||
this.allValuesPromise = new core_1.Promise(function (resolve) { | ||
var callback = _this.providedValues; | ||
var params = { | ||
success: function (values) { | ||
var processedValues = core_1._.toStrings(values); | ||
_this.setIsLoading(false); | ||
_this.valuesType = SetFilterModelValuesType.PROVIDED_LIST; | ||
_this.providedValues = processedValues; | ||
var sortedValues = _this.sortValues(processedValues); | ||
_this.allValues = sortedValues; | ||
resolve(sortedValues); | ||
}, | ||
colDef: _this.colDef | ||
}; | ||
window.setTimeout(function () { return callback(params); }, 0); | ||
}); | ||
break; | ||
} | ||
default: | ||
throw new Error('Unrecognised valuesType'); | ||
} | ||
else { | ||
this.filterValuesExternalPromise = core_1.Promise.external(); | ||
this.filterValuesPromise = this.filterValuesExternalPromise.promise; | ||
this.isLoadingFunc(true); | ||
this.setValues([]); | ||
var callback_1 = this.filterParams.values; | ||
var params_1 = { | ||
success: this.onAsyncValuesLoaded.bind(this), | ||
colDef: this.colDef | ||
}; | ||
window.setTimeout(function () { return callback_1(params_1); }, 0); | ||
} | ||
this.updateAvailableValues(); | ||
}; | ||
SetValueModel.prototype.onAsyncValuesLoaded = function (values) { | ||
this.modelUpdatedFunc(values); | ||
this.isLoadingFunc(false); | ||
this.filterValuesExternalPromise.resolve(values); | ||
}; | ||
SetValueModel.prototype.areValuesSync = function () { | ||
return this.valuesType == SetFilterModelValuesType.PROVIDED_LIST || this.valuesType == SetFilterModelValuesType.NOT_PROVIDED; | ||
}; | ||
SetValueModel.prototype.setValuesType = function (value) { | ||
@@ -123,63 +136,30 @@ this.valuesType = value; | ||
}; | ||
SetValueModel.prototype.setValues = function (valuesToUse) { | ||
this.allUniqueValues = valuesToUse; | ||
if (!this.suppressSorting) { | ||
this.sortValues(this.allUniqueValues); | ||
} | ||
SetValueModel.prototype.isValueAvailable = function (value) { | ||
return this.availableValues.has(value); | ||
}; | ||
SetValueModel.prototype.extractSyncValuesToUse = function () { | ||
var valuesToUse; | ||
if (this.valuesType == SetFilterModelValuesType.PROVIDED_LIST) { | ||
if (Array.isArray(this.filterParams.values)) { | ||
valuesToUse = core_1._.toStrings(this.filterParams.values); | ||
} | ||
else { | ||
// In this case the values are async but have already been resolved, so we can reuse them | ||
valuesToUse = this.allUniqueValues; | ||
} | ||
} | ||
else if (this.valuesType == SetFilterModelValuesType.PROVIDED_CB) { | ||
throw Error("ag-grid: Error extracting values to use. We should not extract the values synchronously when using a callback for the filterParams.values"); | ||
} | ||
else { | ||
var uniqueValuesAsAnyObjects = this.getUniqueValues(false); | ||
valuesToUse = core_1._.toStrings(uniqueValuesAsAnyObjects); | ||
} | ||
return valuesToUse; | ||
SetValueModel.prototype.showAvailableOnly = function () { | ||
return this.valuesType === SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES && | ||
!this.filterParams.suppressRemoveEntries; | ||
}; | ||
SetValueModel.prototype.isValueAvailable = function (value) { | ||
return this.availableUniqueValuesMap[value]; | ||
}; | ||
SetValueModel.prototype.createAvailableUniqueValues = function () { | ||
SetValueModel.prototype.updateAvailableValues = function () { | ||
var _this = this; | ||
var dontCheckAvailableValues = !this.showingAvailableOnly || this.valuesType == SetFilterModelValuesType.PROVIDED_LIST || this.valuesType == SetFilterModelValuesType.PROVIDED_CB; | ||
if (dontCheckAvailableValues) { | ||
this.availableUniqueValues = this.allUniqueValues; | ||
} | ||
else { | ||
var uniqueValuesAsAnyObjects = this.getUniqueValues(true); | ||
this.availableUniqueValues = core_1._.toStrings(uniqueValuesAsAnyObjects); | ||
this.sortValues(this.availableUniqueValues); | ||
} | ||
this.availableUniqueValuesMap = {}; | ||
if (this.availableUniqueValues) { | ||
this.availableUniqueValues.forEach(function (value) { return _this.availableUniqueValuesMap[value] = true; }); | ||
} | ||
this.localEventService.dispatchEvent({ type: SetValueModel.EVENT_AVAILABLE_VALUES_CHANGES }); | ||
this.allValuesPromise.then(function (values) { | ||
var availableValues = _this.showAvailableOnly() ? _this.sortValues(_this.getValuesFromRows(true)) : values; | ||
_this.availableValues = core_1._.convertToSet(availableValues); | ||
_this.localEventService.dispatchEvent({ type: SetValueModel.EVENT_AVAILABLE_VALUES_CHANGED }); | ||
_this.updateDisplayedValues(); | ||
}); | ||
}; | ||
SetValueModel.prototype.sortValues = function (values) { | ||
if (this.filterParams && this.filterParams.comparator) { | ||
values.sort(this.filterParams.comparator); | ||
if (this.suppressSorting) { | ||
return values; | ||
} | ||
else if (this.colDef.comparator) { | ||
values.sort(this.colDef.comparator); | ||
} | ||
else { | ||
values.sort(core_1._.defaultComparator); | ||
} | ||
var comparator = this.filterParams.comparator || | ||
this.colDef.comparator || | ||
core_1._.defaultComparator; | ||
return values.sort(comparator); | ||
}; | ||
SetValueModel.prototype.getUniqueValues = function (filterOutNotAvailable) { | ||
SetValueModel.prototype.getValuesFromRows = function (removeUnavailableValues) { | ||
var _this = this; | ||
var uniqueCheck = {}; | ||
var result = []; | ||
if (removeUnavailableValues === void 0) { removeUnavailableValues = false; } | ||
if (!this.clientSideRowModel) { | ||
@@ -189,54 +169,45 @@ console.error('ag-Grid: Set Filter cannot initialise because you are using a row model that does not contain all rows in the browser. Either use a different filter type, or configure Set Filter such that you provide it with values'); | ||
} | ||
var values = new Set(); | ||
var keyCreator = this.colDef.keyCreator; | ||
this.clientSideRowModel.forEachLeafNode(function (node) { | ||
// only pull values from rows that have data. this means we skip filler group nodes. | ||
if (!node.data) { | ||
if (!node.data || (removeUnavailableValues && !_this.doesRowPassOtherFilters(node))) { | ||
return; | ||
} | ||
var value = _this.valueGetter(node); | ||
if (_this.colDef.keyCreator) { | ||
value = _this.colDef.keyCreator({ value: value }); | ||
if (keyCreator) { | ||
value = keyCreator({ value: value }); | ||
} | ||
if (value === "" || value === undefined) { | ||
value = null; | ||
} | ||
if (filterOutNotAvailable) { | ||
if (!_this.doesRowPassOtherFilters(node)) { | ||
return; | ||
} | ||
} | ||
value = core_1._.makeNull(value); | ||
if (value != null && Array.isArray(value)) { | ||
for (var j = 0; j < value.length; j++) { | ||
addUniqueValueIfMissing(value[j]); | ||
} | ||
core_1._.forEach(value, function (x) { | ||
var formatted = core_1._.toStringOrNull(core_1._.makeNull(x)); | ||
values.add(formatted); | ||
}); | ||
} | ||
else { | ||
addUniqueValueIfMissing(value); | ||
values.add(core_1._.toStringOrNull(value)); | ||
} | ||
}); | ||
function addUniqueValueIfMissing(value) { | ||
if (!uniqueCheck.hasOwnProperty(value)) { | ||
result.push(value); | ||
uniqueCheck[value] = 1; | ||
} | ||
} | ||
return result; | ||
return core_1._.values(values); | ||
}; | ||
//sets mini filter. returns true if it changed from last value, otherwise false | ||
SetValueModel.prototype.setMiniFilter = function (newMiniFilter) { | ||
newMiniFilter = core_1._.makeNull(newMiniFilter); | ||
if (this.miniFilter === newMiniFilter) { | ||
/** Sets mini filter value. Returns true if it changed from last value, otherwise false. */ | ||
SetValueModel.prototype.setMiniFilter = function (value) { | ||
value = core_1._.makeNull(value); | ||
if (this.miniFilterText === value) { | ||
//do nothing if filter has not changed | ||
return false; | ||
} | ||
this.miniFilter = newMiniFilter; | ||
this.processMiniFilter(); | ||
this.miniFilterText = value; | ||
this.updateDisplayedValues(); | ||
return true; | ||
}; | ||
SetValueModel.prototype.getMiniFilter = function () { | ||
return this.miniFilter; | ||
return this.miniFilterText; | ||
}; | ||
SetValueModel.prototype.processMiniFilter = function () { | ||
// if no filter, just use the unique values | ||
if (this.miniFilter === null) { | ||
this.displayedValues = this.availableUniqueValues; | ||
SetValueModel.prototype.updateDisplayedValues = function () { | ||
var _this = this; | ||
// if no filter, just display all available values | ||
if (this.miniFilterText == null) { | ||
this.displayedValues = core_1._.values(this.availableValues); | ||
return; | ||
@@ -246,24 +217,17 @@ } | ||
this.displayedValues = []; | ||
var miniFilter = this.formatter(this.miniFilter); | ||
// make upper case to have search case insensitive | ||
var miniFilterUpperCase = miniFilter.toUpperCase(); | ||
//This function encapsulates the logic to check if a string matches the mini filter | ||
var matchesFn = function (valueToCheck) { | ||
if (valueToCheck == null) { | ||
return false; | ||
} | ||
// allow for case insensitive searches, make both filter and value uppercase | ||
var valueUpperCase = valueToCheck.toUpperCase(); | ||
return valueUpperCase.indexOf(miniFilterUpperCase) >= 0; | ||
// to allow for case insensitive searches, upper-case both filter text and value | ||
var formattedFilterText = this.formatter(this.miniFilterText).toUpperCase(); | ||
var matchesFilter = function (valueToCheck) { | ||
return valueToCheck != null && valueToCheck.toUpperCase().indexOf(formattedFilterText) >= 0; | ||
}; | ||
for (var i = 0, l = this.availableUniqueValues.length; i < l; i++) { | ||
var value = this.availableUniqueValues[i]; | ||
if (value) { | ||
var displayedValue = this.formatter(value.toString()); | ||
var formattedValue = this.valueFormatterService.formatValue(this.column, null, null, displayedValue); | ||
if (matchesFn(displayedValue) || matchesFn(formattedValue)) { | ||
this.displayedValues.push(value); | ||
} | ||
this.availableValues.forEach(function (value) { | ||
if (value == null) { | ||
return; | ||
} | ||
} | ||
var displayedValue = _this.formatter(value); | ||
var formattedValue = _this.valueFormatterService.formatValue(_this.column, null, null, displayedValue); | ||
if (matchesFilter(displayedValue) || matchesFilter(formattedValue)) { | ||
_this.displayedValues.push(value); | ||
} | ||
}); | ||
}; | ||
@@ -276,86 +240,53 @@ SetValueModel.prototype.getDisplayedValueCount = function () { | ||
}; | ||
SetValueModel.prototype.selectAllUsingMiniFilter = function () { | ||
if (this.miniFilter) { | ||
this.selectOn(this.displayedValues); | ||
} | ||
else { | ||
this.selectOn(this.allUniqueValues); | ||
} | ||
SetValueModel.prototype.isFilterActive = function () { | ||
return this.allValues.length !== this.selectedValues.size; | ||
}; | ||
SetValueModel.prototype.selectOn = function (toSelectOn) { | ||
var count = toSelectOn.length; | ||
for (var i = 0; i < count; i++) { | ||
var key = toSelectOn[i]; | ||
var safeKey = this.valueToKey(key); | ||
this.selectedValuesMap[safeKey] = null; | ||
} | ||
this.selectedValuesCount = Object.keys(this.selectedValuesMap).length; | ||
SetValueModel.prototype.getUniqueValueCount = function () { | ||
return this.allValues.length; | ||
}; | ||
SetValueModel.prototype.valueToKey = function (key) { | ||
if (key === null) { | ||
return NULL_VALUE; | ||
} | ||
else { | ||
return key; | ||
} | ||
SetValueModel.prototype.getUniqueValue = function (index) { | ||
return this.allValues[index]; | ||
}; | ||
SetValueModel.prototype.keyToValue = function (value) { | ||
if (value === NULL_VALUE) { | ||
return null; | ||
SetValueModel.prototype.selectAll = function (clearExistingSelection) { | ||
var _this = this; | ||
if (clearExistingSelection === void 0) { clearExistingSelection = false; } | ||
if (this.miniFilterText == null) { | ||
// ensure everything is selected | ||
this.selectedValues = core_1._.convertToSet(this.allValues); | ||
} | ||
else { | ||
return value; | ||
// ensure everything that matches the mini filter is selected | ||
if (clearExistingSelection) { | ||
this.selectedValues.clear(); | ||
} | ||
core_1._.forEach(this.displayedValues, function (value) { return _this.selectValue(value); }); | ||
} | ||
}; | ||
SetValueModel.prototype.isFilterActive = function () { | ||
return this.allUniqueValues.length !== this.selectedValuesCount; | ||
}; | ||
SetValueModel.prototype.selectNothingUsingMiniFilter = function () { | ||
SetValueModel.prototype.selectNothing = function () { | ||
var _this = this; | ||
if (this.miniFilter) { | ||
this.displayedValues.forEach(function (it) { return _this.unselectValue(it); }); | ||
if (this.miniFilterText == null) { | ||
// ensure everything is deselected | ||
this.selectedValues.clear(); | ||
} | ||
else { | ||
this.selectNothing(); | ||
// ensure everything that matches the mini filter is deselected | ||
core_1._.forEach(this.displayedValues, function (it) { return _this.deselectValue(it); }); | ||
} | ||
}; | ||
SetValueModel.prototype.selectNothing = function () { | ||
this.selectedValuesMap = {}; | ||
this.selectedValuesCount = 0; | ||
SetValueModel.prototype.selectValue = function (value) { | ||
this.selectedValues.add(value); | ||
}; | ||
SetValueModel.prototype.getUniqueValueCount = function () { | ||
return this.allUniqueValues.length; | ||
SetValueModel.prototype.deselectValue = function (value) { | ||
this.selectedValues.delete(value); | ||
}; | ||
SetValueModel.prototype.getUniqueValue = function (index) { | ||
return this.allUniqueValues[index]; | ||
}; | ||
SetValueModel.prototype.unselectValue = function (value) { | ||
var safeKey = this.valueToKey(value); | ||
if (this.selectedValuesMap[safeKey] !== undefined) { | ||
delete this.selectedValuesMap[safeKey]; | ||
this.selectedValuesCount--; | ||
} | ||
}; | ||
SetValueModel.prototype.selectAllFromMiniFilter = function () { | ||
this.selectNothing(); | ||
this.selectAllUsingMiniFilter(); | ||
}; | ||
SetValueModel.prototype.selectValue = function (value) { | ||
var safeKey = this.valueToKey(value); | ||
if (this.selectedValuesMap[safeKey] === undefined) { | ||
this.selectedValuesMap[safeKey] = null; | ||
this.selectedValuesCount++; | ||
} | ||
}; | ||
SetValueModel.prototype.isValueSelected = function (value) { | ||
var safeKey = this.valueToKey(value); | ||
return this.selectedValuesMap[safeKey] !== undefined; | ||
return this.selectedValues.has(value); | ||
}; | ||
SetValueModel.prototype.isEverythingSelected = function () { | ||
var _this = this; | ||
if (this.miniFilter) { | ||
return this.displayedValues.filter(function (it) { return _this.isValueSelected(it); }).length === this.displayedValues.length; | ||
if (this.miniFilterText == null) { | ||
return this.allValues.length === this.selectedValues.size; | ||
} | ||
else { | ||
return this.allUniqueValues.length === this.selectedValuesCount; | ||
return core_1._.filter(this.displayedValues, function (it) { return _this.isValueSelected(it); }).length === this.displayedValues.length; | ||
} | ||
@@ -365,59 +296,35 @@ }; | ||
var _this = this; | ||
if (this.miniFilter) { | ||
return this.displayedValues.filter(function (it) { return _this.isValueSelected(it); }).length === 0; | ||
if (this.miniFilterText == null) { | ||
return this.selectedValues.size === 0; | ||
} | ||
else { | ||
return this.selectedValuesCount === 0; | ||
return core_1._.filter(this.displayedValues, function (it) { return _this.isValueSelected(it); }).length === 0; | ||
} | ||
}; | ||
SetValueModel.prototype.getModel = function () { | ||
var _this = this; | ||
if (!this.isFilterActive()) { | ||
return null; | ||
} | ||
var selectedValues = []; | ||
core_1._.iterateObject(this.selectedValuesMap, function (key) { | ||
var value = _this.keyToValue(key); | ||
selectedValues.push(value); | ||
}); | ||
return selectedValues; | ||
return this.isFilterActive() ? core_1._.values(this.selectedValues) : null; | ||
}; | ||
SetValueModel.prototype.setModel = function (model, isSelectAll) { | ||
SetValueModel.prototype.setModel = function (model) { | ||
var _this = this; | ||
if (isSelectAll === void 0) { isSelectAll = false; } | ||
if (this.areValuesSync()) { | ||
this.setSyncModel(model, isSelectAll); | ||
} | ||
else { | ||
this.filterValuesExternalPromise.promise.then(function (values) { | ||
_this.setSyncModel(model, isSelectAll); | ||
_this.modelUpdatedFunc(values, model); | ||
}); | ||
} | ||
}; | ||
SetValueModel.prototype.setSyncModel = function (model, isSelectAll) { | ||
if (isSelectAll === void 0) { isSelectAll = false; } | ||
if (model && !isSelectAll) { | ||
this.selectNothingUsingMiniFilter(); | ||
for (var i = 0; i < model.length; i++) { | ||
var rawValue = model[i]; | ||
var value = this.keyToValue(rawValue); | ||
if (this.allUniqueValues.indexOf(value) >= 0) { | ||
this.selectValue(value); | ||
} | ||
this.allValuesPromise.then(function (values) { | ||
if (model == null) { | ||
// reset to everything selected | ||
_this.selectedValues = core_1._.convertToSet(values); | ||
} | ||
} | ||
else { | ||
this.selectAllUsingMiniFilter(); | ||
} | ||
else { | ||
// select all values from the model that exist in the filter | ||
_this.selectedValues.clear(); | ||
var allValues_1 = core_1._.convertToSet(values); | ||
core_1._.forEach(model, function (value) { | ||
if (allValues_1.has(value)) { | ||
_this.selectValue(value); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
SetValueModel.prototype.onFilterValuesReady = function (callback) { | ||
//This guarantees that if the user is racing to set values async into the set filter, only the first instance | ||
//will be used | ||
// ie Values are async and the user manually wants to override them before the retrieval of values is triggered | ||
// (set filter values in the following example) | ||
// http://plnkr.co/edit/eFka7ynvPj68tL3VJFWf?p=preview | ||
this.filterValuesPromise.firstOneOnly(callback); | ||
this.allValuesPromise.then(callback); | ||
}; | ||
SetValueModel.EVENT_AVAILABLE_VALUES_CHANGES = 'availableValuesChanged'; | ||
SetValueModel.EVENT_AVAILABLE_VALUES_CHANGED = 'availableValuesChanged'; | ||
return SetValueModel; | ||
@@ -424,0 +331,0 @@ }()); |
@@ -1,2 +0,2 @@ | ||
import { Module } from "@ag-grid-community/core"; | ||
import { Module } from '@ag-grid-community/core'; | ||
export declare const SetFilterModule: Module; |
@@ -1,2 +0,2 @@ | ||
export { SetFilterModule } from "./setFilterModule"; | ||
export { SetFilter } from "./setFilter/setFilter"; | ||
export { SetFilterModule } from './setFilterModule'; | ||
export { SetFilter } from './setFilter/setFilter'; |
@@ -1,2 +0,2 @@ | ||
export { SetFilterModule } from "./setFilterModule"; | ||
export { SetFilter } from "./setFilter/setFilter"; | ||
export { SetFilterModule } from './setFilterModule'; | ||
export { SetFilter } from './setFilter/setFilter'; |
@@ -1,8 +0,7 @@ | ||
import { IDoesFilterPassParams, ISetFilterParams, ProvidedFilter } from "@ag-grid-community/core"; | ||
import { SetValueModel } from "./setValueModel"; | ||
import { SetFilterModel } from "./setFilterModel"; | ||
import { IDoesFilterPassParams, ISetFilterParams, ProvidedFilter, IAfterGuiAttachedParams } from '@ag-grid-community/core'; | ||
import { SetValueModel } from './setValueModel'; | ||
import { SetFilterModel } from './setFilterModel'; | ||
export declare class SetFilter extends ProvidedFilter { | ||
private valueModel; | ||
private eSelectAll; | ||
private eSelectAllContainer; | ||
private eMiniFilter; | ||
@@ -12,6 +11,6 @@ private eFilterLoading; | ||
private eventService; | ||
private selectAllState; | ||
private selectAllState?; | ||
private setFilterParams; | ||
private virtualList; | ||
private appliedModelValuesMapped; | ||
private appliedModelValues; | ||
protected updateUiVisibility(): void; | ||
@@ -27,10 +26,13 @@ protected createBodyTemplate(): string; | ||
private checkSetFilterDeprecatedParams; | ||
private addEventListenersForDataChanges; | ||
/** Called when the data in the grid changes, to prompt the set filter values to be updated. */ | ||
private syncValuesAfterDataChange; | ||
private setupSyncValuesAfterDataChange; | ||
private updateCheckboxIcon; | ||
setLoading(loading: boolean): void; | ||
private initialiseFilterBodyUi; | ||
private initVirtualList; | ||
private createSetListItem; | ||
afterGuiAttached(params: any): void; | ||
refreshVirtualList(): void; | ||
private initMiniFilter; | ||
private initSelectAll; | ||
afterGuiAttached(params: IAfterGuiAttachedParams): void; | ||
applyModel(): boolean; | ||
@@ -47,6 +49,5 @@ doesFilterPass(params: IDoesFilterPassParams): boolean; | ||
*/ | ||
setFilterValues(options: string[], selectAll?: boolean, notify?: boolean, toSelect?: string[]): void; | ||
setFilterValues(options: string[]): void; | ||
/** | ||
* Public method provided so the user can reset the values of the filter once that it has started | ||
* @param options The options to use. | ||
* Public method provided so the user can reset the values of the filter once that it has started. | ||
*/ | ||
@@ -57,14 +58,13 @@ resetFilterValues(): void; | ||
private onMiniFilterKeyPress; | ||
private onEnterKeyOnMiniFilter; | ||
private onMiniFilterInput; | ||
private onSelectAll; | ||
private doSelectAll; | ||
private onItemSelected; | ||
setMiniFilter(newMiniFilter: any): void; | ||
setMiniFilter(newMiniFilter: string): void; | ||
getMiniFilter(): string; | ||
selectEverything(): void; | ||
selectNothing(): void; | ||
unselectValue(value: any): void; | ||
selectValue(value: any): void; | ||
isValueSelected(value: any): boolean; | ||
unselectValue(value: string): void; | ||
selectValue(value: string): void; | ||
private refresh; | ||
isValueSelected(value: string): boolean; | ||
isEverythingSelected(): boolean; | ||
@@ -74,2 +74,3 @@ isNothingSelected(): boolean; | ||
getUniqueValue(index: any): string; | ||
refreshVirtualList(): void; | ||
} |
@@ -20,11 +20,16 @@ var __extends = (this && this.__extends) || (function () { | ||
}; | ||
import { Autowired, Constants, Events, ProvidedFilter, RefSelector, VirtualList, _ } from "@ag-grid-community/core"; | ||
import { SetFilterModelValuesType, SetValueModel } from "./setValueModel"; | ||
import { SetFilterListItem } from "./setFilterListItem"; | ||
import { Autowired, Constants, Events, ProvidedFilter, RefSelector, VirtualList, _ } from '@ag-grid-community/core'; | ||
import { SetFilterModelValuesType, SetValueModel } from './setValueModel'; | ||
import { SetFilterListItem } from './setFilterListItem'; | ||
var SetFilter = /** @class */ (function (_super) { | ||
__extends(SetFilter, _super); | ||
function SetFilter() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
// To make the filtering super fast, we store the values in an object, and check for the boolean value. | ||
// Although Set would be a more natural choice of data structure, its performance across browsers is | ||
// significantly worse than using an object: https://jsbench.me/hdk91jbw1h/ | ||
_this.appliedModelValues = null; | ||
return _this; | ||
} | ||
// unlike the simple filter's, nothing in the set filter UI shows/hides. | ||
// unlike the simple filters, nothing in the set filter UI shows/hides. | ||
// maybe this method belongs in abstractSimpleFilter??? | ||
@@ -34,3 +39,3 @@ SetFilter.prototype.updateUiVisibility = function () { }; | ||
var translate = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
return "<div ref=\"eFilterLoading\" class=\"ag-filter-loading ag-hidden\">" + translate('loadingOoo', 'Loading...') + "</div>\n <div>\n <div class=\"ag-filter-header-container\" role=\"presentation\">\n <ag-input-text-field class=\"ag-mini-filter\" ref=\"eMiniFilter\"></ag-input-text-field>\n <label ref=\"eSelectAllContainer\" class=\"ag-set-filter-item ag-set-filter-select-all\">\n <ag-checkbox ref=\"eSelectAll\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox><span class=\"ag-set-filter-item-value\">(" + translate('selectAll', 'Select All') + ")</span>\n </label>\n </div>\n <div ref=\"eSetFilterList\" class=\"ag-set-filter-list\" role=\"presentation\"></div>\n </div>"; | ||
return /* html */ "\n <div ref=\"eFilterLoading\" class=\"ag-filter-loading ag-hidden\">" + translate('loadingOoo', 'Loading...') + "</div>\n <div>\n <div class=\"ag-filter-header-container\" role=\"presentation\">\n <ag-input-text-field class=\"ag-mini-filter\" ref=\"eMiniFilter\"></ag-input-text-field>\n <label ref=\"eSelectAllContainer\" class=\"ag-set-filter-item ag-set-filter-select-all\">\n <ag-checkbox ref=\"eSelectAll\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox><span class=\"ag-set-filter-item-value\">(" + translate('selectAll', 'Select All') + ")</span>\n </label>\n </div>\n <div ref=\"eSetFilterList\" class=\"ag-set-filter-list\" role=\"presentation\"></div>\n </div>"; | ||
}; | ||
@@ -42,3 +47,2 @@ SetFilter.prototype.getCssIdentifier = function () { | ||
this.setMiniFilter(null); | ||
this.valueModel.setModel(null, true); | ||
this.selectEverything(); | ||
@@ -58,6 +62,5 @@ }; | ||
// also supporting old filter model for backwards compatibility | ||
var newValues = (model instanceof Array) ? model : model.values; | ||
var newValues = model instanceof Array ? model : model.values; | ||
this.valueModel.setModel(newValues); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.refresh(); | ||
}; | ||
@@ -80,35 +83,20 @@ SetFilter.prototype.getModelFromUi = function () { | ||
// both are missing | ||
if (!a && !b) { | ||
if (a == null && b == null) { | ||
return true; | ||
} | ||
// one is missing, other present | ||
if ((!a && b) || (a && !b)) { | ||
return false; | ||
} | ||
// both present, so compare | ||
// if different sizes, they are different | ||
if (a.values.length != b.values.length) { | ||
return false; | ||
} | ||
// now check each one value by value | ||
for (var i = 0; i < a.values.length; i++) { | ||
if (a.values[i] !== b.values[i]) { | ||
return false; | ||
} | ||
} | ||
// got this far means value lists are identical | ||
return true; | ||
return a != null && b != null && _.areEqual(a.values, b.values); | ||
}; | ||
SetFilter.prototype.setParams = function (params) { | ||
var _this = this; | ||
_super.prototype.setParams.call(this, params); | ||
this.checkSetFilterDeprecatedParams(params); | ||
this.setFilterParams = params; | ||
this.valueModel = new SetValueModel(params.colDef, params.rowModel, params.valueGetter, params.doesRowPassOtherFilter, params.suppressSorting, function (loading) { return _this.setLoading(loading); }, this.valueFormatterService, params.column); | ||
this.initialiseFilterBodyUi(); | ||
var syncValuesAfterDataChange = !params.suppressSyncValuesAfterDataChange && | ||
// sync values only with CSRM | ||
this.rowModel.getType() === Constants.ROW_MODEL_TYPE_CLIENT_SIDE && | ||
// sync only needed if user not providing values | ||
!params.values; | ||
this.valueModel.onFilterValuesReady(function () { return _this.refresh(); }); | ||
var syncValuesAfterDataChange = this.rowModel.getType() === Constants.ROW_MODEL_TYPE_CLIENT_SIDE && | ||
!params.values && | ||
!params.suppressSyncValuesAfterDataChange; | ||
if (syncValuesAfterDataChange) { | ||
this.setupSyncValuesAfterDataChange(); | ||
this.addEventListenersForDataChanges(); | ||
} | ||
@@ -128,18 +116,16 @@ }; | ||
} | ||
if (params.suppressSyncValuesAfterDataChange) { | ||
var message_4 = 'ag-Grid: since version 23.1, the Set Filter param suppressSyncValuesAfterDataChange has' + | ||
' been deprecated and will be removed in a future major release.'; | ||
_.doOnce(function () { return console.warn(message_4); }, 'suppressSyncValuesAfterDataChange deprecated'); | ||
} | ||
if (params.suppressRemoveEntries) { | ||
var message_5 = 'ag-Grid: since version 23.1, the Set Filter param suppressRemoveEntries has' + | ||
' been deprecated and will be removed in a future major release.'; | ||
_.doOnce(function () { return console.warn(message_5); }, 'suppressRemoveEntries deprecated'); | ||
} | ||
}; | ||
// gets called with change to data values, thus need to update the values available for selection | ||
// in the set filter. | ||
SetFilter.prototype.syncValuesAfterDataChange = function () { | ||
var everythingSelected = !this.getModel(); | ||
this.valueModel.refreshAfterNewRowsLoaded(true, everythingSelected); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.onBtApply(false, true); | ||
}; | ||
// this keeps the filter up to date with changes in the row data | ||
SetFilter.prototype.setupSyncValuesAfterDataChange = function () { | ||
SetFilter.prototype.addEventListenersForDataChanges = function () { | ||
var _this = this; | ||
// add listener for when data is changed via transaction update (includes delta row mode | ||
// as this uses transaction updates) | ||
this.addDestroyableEventListener(this.eventService, Events.EVENT_ROW_DATA_UPDATED, this.syncValuesAfterDataChange.bind(this)); | ||
this.addDestroyableEventListener(this.eventService, Events.EVENT_ROW_DATA_UPDATED, function () { return _this.syncValuesAfterDataChange(); }); | ||
this.addDestroyableEventListener(this.eventService, Events.EVENT_CELL_VALUE_CHANGED, function (event) { | ||
@@ -153,2 +139,9 @@ // only interested in changes to do with this column | ||
}; | ||
/** Called when the data in the grid changes, to prompt the set filter values to be updated. */ | ||
SetFilter.prototype.syncValuesAfterDataChange = function (keepSelection) { | ||
if (keepSelection === void 0) { keepSelection = true; } | ||
this.valueModel.refetchValues(keepSelection); | ||
this.refresh(); | ||
this.onBtApply(false, true); | ||
}; | ||
SetFilter.prototype.updateCheckboxIcon = function () { | ||
@@ -161,25 +154,46 @@ this.eSelectAll.setValue(this.selectAllState); | ||
SetFilter.prototype.initialiseFilterBodyUi = function () { | ||
this.initVirtualList(); | ||
this.initMiniFilter(); | ||
this.initSelectAll(); | ||
}; | ||
SetFilter.prototype.initVirtualList = function () { | ||
var _this = this; | ||
this.virtualList = new VirtualList('filter'); | ||
this.getContext().wireBean(this.virtualList); | ||
var virtualList = this.virtualList = this.wireBean(new VirtualList('filter')); | ||
var eSetFilterList = this.getRefElement('eSetFilterList'); | ||
if (eSetFilterList) { | ||
eSetFilterList.appendChild(this.virtualList.getGui()); | ||
eSetFilterList.appendChild(virtualList.getGui()); | ||
} | ||
if (_.exists(this.setFilterParams.cellHeight)) { | ||
this.virtualList.setRowHeight(this.setFilterParams.cellHeight); | ||
var cellHeight = this.setFilterParams.cellHeight; | ||
if (cellHeight != null) { | ||
virtualList.setRowHeight(cellHeight); | ||
} | ||
this.virtualList.setComponentCreator(this.createSetListItem.bind(this)); | ||
this.valueModel = new SetValueModel(this.setFilterParams.colDef, this.setFilterParams.rowModel, this.setFilterParams.valueGetter, this.setFilterParams.doesRowPassOtherFilter, this.setFilterParams.suppressSorting, function (values, toSelect) { return _this.setFilterValues(values, toSelect ? false : true, toSelect ? true : false, toSelect); }, this.setLoading.bind(this), this.valueFormatterService, this.setFilterParams.column); | ||
this.virtualList.setModel(new ModelWrapper(this.valueModel)); | ||
_.setDisplayed(this.eMiniFilter.getGui(), !this.setFilterParams.suppressMiniFilter); | ||
this.eMiniFilter.setValue(this.valueModel.getMiniFilter()); | ||
this.eMiniFilter.onValueChange(function () { return _this.onMiniFilterInput(); }); | ||
this.addDestroyableEventListener(this.eMiniFilter.getInputElement(), 'keypress', this.onMiniFilterKeyPress.bind(this)); | ||
virtualList.setComponentCreator(function (value) { return _this.createSetListItem(value); }); | ||
virtualList.setModel(new ModelWrapper(this.valueModel)); | ||
}; | ||
SetFilter.prototype.createSetListItem = function (value) { | ||
var _this = this; | ||
var listItem = this.wireBean(new SetFilterListItem(value, this.setFilterParams)); | ||
var selected = this.valueModel.isValueSelected(value); | ||
listItem.setSelected(selected); | ||
listItem.addEventListener(SetFilterListItem.EVENT_SELECTED, function () { return _this.onItemSelected(value, listItem.isSelected()); }); | ||
return listItem; | ||
}; | ||
SetFilter.prototype.initMiniFilter = function () { | ||
var _this = this; | ||
var eMiniFilter = this.eMiniFilter; | ||
_.setDisplayed(eMiniFilter.getGui(), !this.setFilterParams.suppressMiniFilter); | ||
eMiniFilter.setValue(this.valueModel.getMiniFilter()); | ||
eMiniFilter.onValueChange(function () { return _this.onMiniFilterInput(); }); | ||
this.addDestroyableEventListener(eMiniFilter.getInputElement(), 'keypress', function (e) { return _this.onMiniFilterKeyPress(e); }); | ||
}; | ||
SetFilter.prototype.initSelectAll = function () { | ||
var _this = this; | ||
this.updateCheckboxIcon(); | ||
this.addDestroyableEventListener(this.eSelectAllContainer, 'click', this.onSelectAll.bind(this)); | ||
this.updateSelectAll(); | ||
var eSelectAllContainer = this.getRefElement('eSelectAllContainer'); | ||
if (this.setFilterParams.suppressSelectAll) { | ||
_.setDisplayed(this.eSelectAllContainer, false); | ||
_.setDisplayed(eSelectAllContainer, false); | ||
} | ||
else { | ||
this.addDestroyableEventListener(eSelectAllContainer, 'click', function (e) { return _this.onSelectAll(e); }); | ||
} | ||
this.addDestroyableEventListener(this.eSelectAll.getInputElement(), 'keydown', function (e) { | ||
@@ -191,18 +205,7 @@ if (e.keyCode === Constants.KEY_SPACE) { | ||
}); | ||
this.virtualList.refresh(); | ||
}; | ||
SetFilter.prototype.createSetListItem = function (value) { | ||
var _this = this; | ||
var listItem = new SetFilterListItem(value, this.setFilterParams.column); | ||
this.getContext().wireBean(listItem); | ||
var selected = this.valueModel.isValueSelected(value); | ||
listItem.setSelected(selected); | ||
listItem.addEventListener(SetFilterListItem.EVENT_SELECTED, function () { | ||
_this.onItemSelected(value, listItem.isSelected()); | ||
}); | ||
return listItem; | ||
}; | ||
// we need to have the gui attached before we can draw the virtual rows, as the | ||
// virtual row logic needs info about the gui state | ||
// we need to have the GUI attached before we can draw the virtual rows, as the | ||
// virtual row logic needs info about the GUI state | ||
SetFilter.prototype.afterGuiAttached = function (params) { | ||
_super.prototype.afterGuiAttached.call(this, params); | ||
var _a = this, virtualList = _a.virtualList, eMiniFilter = _a.eMiniFilter; | ||
@@ -214,43 +217,37 @@ var translate = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
}; | ||
SetFilter.prototype.refreshVirtualList = function () { | ||
this.virtualList.refresh(); | ||
}; | ||
SetFilter.prototype.applyModel = function () { | ||
var _this = this; | ||
var res = _super.prototype.applyModel.call(this); | ||
var result = _super.prototype.applyModel.call(this); | ||
// keep the appliedModelValuesMapped in sync with the applied model | ||
var appliedModel = this.getModel(); | ||
if (appliedModel) { | ||
this.appliedModelValuesMapped = {}; | ||
appliedModel.values.forEach(function (value) { return _this.appliedModelValuesMapped[value] = true; }); | ||
this.appliedModelValues = {}; | ||
_.forEach(appliedModel.values, function (value) { return _this.appliedModelValues[value] = true; }); | ||
} | ||
else { | ||
this.appliedModelValuesMapped = undefined; | ||
this.appliedModelValues = null; | ||
} | ||
return res; | ||
return result; | ||
}; | ||
SetFilter.prototype.doesFilterPass = function (params) { | ||
// should never happen, if filter model not set, then this method should never be called | ||
if (!this.appliedModelValuesMapped) { | ||
var _this = this; | ||
if (this.appliedModelValues == null) { | ||
return true; | ||
} | ||
var value = this.setFilterParams.valueGetter(params.node); | ||
if (this.setFilterParams.colDef.keyCreator) { | ||
value = this.setFilterParams.colDef.keyCreator({ value: value }); | ||
var _a = this.setFilterParams, valueGetter = _a.valueGetter, keyCreator = _a.colDef.keyCreator; | ||
var value = valueGetter(params.node); | ||
if (keyCreator) { | ||
value = keyCreator({ value: value }); | ||
} | ||
value = _.makeNull(value); | ||
if (Array.isArray(value)) { | ||
for (var i = 0; i < value.length; i++) { | ||
var valueExistsInMap = !!this.appliedModelValuesMapped[value[i]]; | ||
if (valueExistsInMap) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return _.some(value, function (v) { return _this.appliedModelValues[_.makeNull(v)] === true; }); | ||
} | ||
return !!this.appliedModelValuesMapped[value]; | ||
// Comparing against a value performs better than just checking for undefined | ||
// https://jsbench.me/hdk91jbw1h/ | ||
return this.appliedModelValues[value] === true; | ||
}; | ||
SetFilter.prototype.onNewRowsLoaded = function () { | ||
var valuesType = this.valueModel.getValuesType(); | ||
var valuesTypeProvided = valuesType === SetFilterModelValuesType.PROVIDED_CB || | ||
var valuesTypeProvided = valuesType === SetFilterModelValuesType.PROVIDED_CALLBACK || | ||
valuesType === SetFilterModelValuesType.PROVIDED_LIST; | ||
@@ -263,8 +260,3 @@ // if the user is providing values, and we are keeping the previous selection, then | ||
} | ||
var everythingSelected = !this.getModel(); | ||
// default is reset | ||
this.valueModel.refreshAfterNewRowsLoaded(keepSelection, everythingSelected); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.onBtApply(false, true); | ||
this.syncValuesAfterDataChange(keepSelection); | ||
}; | ||
@@ -280,17 +272,8 @@ //noinspection JSUnusedGlobalSymbols | ||
*/ | ||
SetFilter.prototype.setFilterValues = function (options, selectAll, notify, toSelect) { | ||
SetFilter.prototype.setFilterValues = function (options) { | ||
var _this = this; | ||
if (selectAll === void 0) { selectAll = false; } | ||
if (notify === void 0) { notify = true; } | ||
this.valueModel.overrideValues(options, this.isNewRowsActionKeep()); | ||
this.valueModel.onFilterValuesReady(function () { | ||
var keepSelection = _this.setFilterParams && _this.setFilterParams.newRowsAction === 'keep'; | ||
_this.valueModel.setValuesType(SetFilterModelValuesType.PROVIDED_LIST); | ||
_this.valueModel.refreshValues(options, keepSelection, selectAll); | ||
_this.updateSelectAll(); | ||
var actualToSelect = toSelect ? toSelect : options; | ||
actualToSelect.forEach(function (option) { return _this.valueModel.selectValue(option); }); | ||
_this.virtualList.refresh(); | ||
if (notify) { | ||
_this.onUiChanged(); | ||
} | ||
_this.refresh(); | ||
_this.onUiChanged(); | ||
}); | ||
@@ -300,7 +283,6 @@ }; | ||
/** | ||
* Public method provided so the user can reset the values of the filter once that it has started | ||
* @param options The options to use. | ||
* Public method provided so the user can reset the values of the filter once that it has started. | ||
*/ | ||
SetFilter.prototype.resetFilterValues = function () { | ||
this.valueModel.setValuesType(SetFilterModelValuesType.NOT_PROVIDED); | ||
this.valueModel.setValuesType(SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES); | ||
this.onNewRowsLoaded(); | ||
@@ -326,14 +308,9 @@ }; | ||
if (_.isKeyPressed(e, Constants.KEY_ENTER)) { | ||
this.onEnterKeyOnMiniFilter(); | ||
this.valueModel.selectAll(true); | ||
this.refresh(); | ||
this.onUiChanged(true); | ||
} | ||
}; | ||
SetFilter.prototype.onEnterKeyOnMiniFilter = function () { | ||
this.valueModel.selectAllFromMiniFilter(); | ||
this.virtualList.refresh(); | ||
this.updateSelectAll(); | ||
this.onUiChanged(true); | ||
}; | ||
SetFilter.prototype.onMiniFilterInput = function () { | ||
var miniFilterChanged = this.valueModel.setMiniFilter(this.eMiniFilter.getValue()); | ||
if (miniFilterChanged) { | ||
if (this.valueModel.setMiniFilter(this.eMiniFilter.getValue())) { | ||
this.virtualList.refresh(); | ||
@@ -346,21 +323,11 @@ } | ||
_.addAgGridEventPath(event); | ||
if (this.selectAllState === true) { | ||
this.selectAllState = false; | ||
this.selectAllState = !this.selectAllState; | ||
if (this.selectAllState) { | ||
this.valueModel.selectAll(); | ||
} | ||
else { | ||
this.selectAllState = true; | ||
this.valueModel.selectNothing(); | ||
} | ||
this.doSelectAll(); | ||
}; | ||
SetFilter.prototype.doSelectAll = function () { | ||
var checked = this.selectAllState === true; | ||
if (checked) { | ||
this.valueModel.selectAllUsingMiniFilter(); | ||
} | ||
else { | ||
this.valueModel.selectNothingUsingMiniFilter(); | ||
} | ||
this.virtualList.refresh(); | ||
this.refresh(); | ||
this.onUiChanged(); | ||
this.updateSelectAll(); | ||
}; | ||
@@ -372,3 +339,3 @@ SetFilter.prototype.onItemSelected = function (value, selected) { | ||
else { | ||
this.valueModel.unselectValue(value); | ||
this.valueModel.deselectValue(value); | ||
} | ||
@@ -386,20 +353,20 @@ this.updateSelectAll(); | ||
SetFilter.prototype.selectEverything = function () { | ||
this.valueModel.selectAllUsingMiniFilter(); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.valueModel.selectAll(); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.selectNothing = function () { | ||
this.valueModel.selectNothingUsingMiniFilter(); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.valueModel.selectNothing(); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.unselectValue = function (value) { | ||
this.valueModel.unselectValue(value); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
this.valueModel.deselectValue(value); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.selectValue = function (value) { | ||
this.valueModel.selectValue(value); | ||
this.refresh(); | ||
}; | ||
SetFilter.prototype.refresh = function () { | ||
this.virtualList.refresh(); | ||
this.updateSelectAll(); | ||
this.virtualList.refresh(); | ||
}; | ||
@@ -421,2 +388,5 @@ SetFilter.prototype.isValueSelected = function (value) { | ||
}; | ||
SetFilter.prototype.refreshVirtualList = function () { | ||
this.virtualList.refresh(); | ||
}; | ||
__decorate([ | ||
@@ -426,5 +396,2 @@ RefSelector('eSelectAll') | ||
__decorate([ | ||
RefSelector('eSelectAllContainer') | ||
], SetFilter.prototype, "eSelectAllContainer", void 0); | ||
__decorate([ | ||
RefSelector('eMiniFilter') | ||
@@ -431,0 +398,0 @@ ], SetFilter.prototype, "eMiniFilter", void 0); |
@@ -1,5 +0,7 @@ | ||
import { AgEvent, Column, Component } from "@ag-grid-community/core"; | ||
import { AgEvent, ColDef, Component, ISetFilterParams } from '@ag-grid-community/core'; | ||
export interface SelectedEvent extends AgEvent { | ||
} | ||
export declare class SetFilterListItem extends Component { | ||
private readonly value; | ||
private readonly params; | ||
static EVENT_SELECTED: string; | ||
@@ -9,9 +11,8 @@ private gridOptionsWrapper; | ||
private userComponentFactory; | ||
private eFilterItemValue; | ||
private static TEMPLATE; | ||
private eCheckbox; | ||
private selected; | ||
private value; | ||
private column; | ||
constructor(value: any, column: Column); | ||
private useCellRenderer; | ||
private tooltipText; | ||
constructor(value: any, params: ISetFilterParams); | ||
private init; | ||
@@ -22,3 +23,6 @@ isSelected(): boolean; | ||
render(): void; | ||
private getFilterValueFormatter; | ||
private getFormattedValue; | ||
private renderCell; | ||
getComponentHolder(): ColDef; | ||
getTooltipText(): string; | ||
} |
@@ -20,28 +20,12 @@ var __extends = (this && this.__extends) || (function () { | ||
}; | ||
import { Autowired, Component, PostConstruct, RefSelector, _ } from "@ag-grid-community/core"; | ||
import { Autowired, Component, PostConstruct, RefSelector, _, TooltipFeature, } from '@ag-grid-community/core'; | ||
var SetFilterListItem = /** @class */ (function (_super) { | ||
__extends(SetFilterListItem, _super); | ||
function SetFilterListItem(value, column) { | ||
function SetFilterListItem(value, params) { | ||
var _this = _super.call(this, SetFilterListItem.TEMPLATE) || this; | ||
_this.value = value; | ||
_this.params = params; | ||
_this.selected = true; | ||
_this.value = value; | ||
_this.column = column; | ||
return _this; | ||
} | ||
SetFilterListItem.prototype.useCellRenderer = function (target, eTarget, params) { | ||
var cellRendererPromise = this.userComponentFactory.newCellRenderer(target.filterParams, params); | ||
if (cellRendererPromise != null) { | ||
_.bindCellRendererToHtmlElement(cellRendererPromise, eTarget); | ||
} | ||
else { | ||
if (params.valueFormatted == null && params.value == null) { | ||
var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
eTarget.innerText = '(' + localeTextFunc('blanks', 'Blanks') + ')'; | ||
} | ||
else { | ||
eTarget.innerText = params.valueFormatted != null ? params.valueFormatted : params.value; | ||
} | ||
} | ||
return cellRendererPromise; | ||
}; | ||
SetFilterListItem.prototype.init = function () { | ||
@@ -69,17 +53,44 @@ var _this = this; | ||
SetFilterListItem.prototype.render = function () { | ||
var _this = this; | ||
var valueElement = this.queryForHtmlElement('.ag-set-filter-item-value'); | ||
var colDef = this.column.getColDef(); | ||
var filterValueFormatter = this.getFilterValueFormatter(colDef); | ||
var valueFormatted = this.valueFormatterService.formatValue(this.column, null, null, this.value, filterValueFormatter); | ||
var _a = this, value = _a.value, _b = _a.params, column = _b.column, colDef = _b.colDef; | ||
var formattedValue = this.getFormattedValue(colDef, column, value); | ||
if (this.params.showTooltips) { | ||
this.tooltipText = _.escape(formattedValue != null ? formattedValue : value); | ||
if (_.exists(this.tooltipText)) { | ||
if (this.gridOptionsWrapper.isEnableBrowserTooltips()) { | ||
this.eFilterItemValue.title = this.tooltipText; | ||
} | ||
else { | ||
this.addFeature(new TooltipFeature(this, 'setFilterValue')); | ||
} | ||
} | ||
} | ||
var params = { | ||
value: this.value, | ||
valueFormatted: valueFormatted, | ||
value: value, | ||
valueFormatted: formattedValue, | ||
api: this.gridOptionsWrapper.getApi() | ||
}; | ||
var componentPromise = this.useCellRenderer(colDef, valueElement, params); | ||
if (!componentPromise) { | ||
this.renderCell(colDef, this.eFilterItemValue, params); | ||
}; | ||
SetFilterListItem.prototype.getFormattedValue = function (colDef, column, value) { | ||
var filterParams = colDef.filterParams; | ||
var formatter = filterParams == null ? null : filterParams.valueFormatter; | ||
return this.valueFormatterService.formatValue(column, null, null, value, formatter, false); | ||
}; | ||
SetFilterListItem.prototype.renderCell = function (target, eTarget, params) { | ||
var _this = this; | ||
var filterParams = target.filterParams; | ||
var cellRendererPromise = this.userComponentFactory.newSetFilterCellRenderer(filterParams, params); | ||
if (cellRendererPromise == null) { | ||
var valueToRender = params.valueFormatted == null ? params.value : params.valueFormatted; | ||
if (valueToRender == null) { | ||
var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc(); | ||
eTarget.innerText = "(" + localeTextFunc('blanks', 'Blanks') + ")"; | ||
} | ||
else { | ||
eTarget.innerText = valueToRender; | ||
} | ||
return; | ||
} | ||
componentPromise.then(function (component) { | ||
_.bindCellRendererToHtmlElement(cellRendererPromise, eTarget); | ||
cellRendererPromise.then(function (component) { | ||
if (component && component.destroy) { | ||
@@ -90,7 +101,10 @@ _this.addDestroyFunc(component.destroy.bind(component)); | ||
}; | ||
SetFilterListItem.prototype.getFilterValueFormatter = function (colDef) { | ||
return colDef.filterParams ? colDef.filterParams.valueFormatter : undefined; | ||
SetFilterListItem.prototype.getComponentHolder = function () { | ||
return this.params.column.getColDef(); | ||
}; | ||
SetFilterListItem.prototype.getTooltipText = function () { | ||
return this.tooltipText; | ||
}; | ||
SetFilterListItem.EVENT_SELECTED = 'selected'; | ||
SetFilterListItem.TEMPLATE = "<label class=\"ag-set-filter-item\">\n <ag-checkbox ref=\"eCheckbox\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox>\n <span class=\"ag-set-filter-item-value\"></span>\n </label>"; | ||
SetFilterListItem.TEMPLATE = "\n <label class=\"ag-set-filter-item\">\n <ag-checkbox ref=\"eCheckbox\" class=\"ag-set-filter-item-checkbox\"></ag-checkbox>\n <span ref=\"eFilterItemValue\" class=\"ag-set-filter-item-value\"></span>\n </label>"; | ||
__decorate([ | ||
@@ -106,2 +120,5 @@ Autowired('gridOptionsWrapper') | ||
__decorate([ | ||
RefSelector('eFilterItemValue') | ||
], SetFilterListItem.prototype, "eFilterItemValue", void 0); | ||
__decorate([ | ||
RefSelector('eCheckbox') | ||
@@ -108,0 +125,0 @@ ], SetFilterListItem.prototype, "eCheckbox", void 0); |
@@ -1,4 +0,4 @@ | ||
import { ProvidedFilterModel } from "@ag-grid-community/core"; | ||
import { ProvidedFilterModel } from '@ag-grid-community/core'; | ||
export interface SetFilterModel extends ProvidedFilterModel { | ||
values: string[]; | ||
} |
@@ -1,3 +0,3 @@ | ||
import { FilterChangedEvent, Component, IFloatingFilter, IFloatingFilterParams } from "@ag-grid-community/core"; | ||
import { SetFilterModel } from "./setFilterModel"; | ||
import { FilterChangedEvent, Component, IFloatingFilter, IFloatingFilterParams } from '@ag-grid-community/core'; | ||
import { SetFilterModel } from './setFilterModel'; | ||
export declare class SetFloatingFilterComp extends Component implements IFloatingFilter { | ||
@@ -4,0 +4,0 @@ private eFloatingFilterText; |
@@ -20,8 +20,8 @@ var __extends = (this && this.__extends) || (function () { | ||
}; | ||
import { Autowired, Component, RefSelector } from "@ag-grid-community/core"; | ||
import { SetValueModel } from "./setValueModel"; | ||
import { Autowired, Component, RefSelector, _ } from '@ag-grid-community/core'; | ||
import { SetValueModel } from './setValueModel'; | ||
var SetFloatingFilterComp = /** @class */ (function (_super) { | ||
__extends(SetFloatingFilterComp, _super); | ||
function SetFloatingFilterComp() { | ||
var _this = _super.call(this, "<div class=\"ag-floating-filter-input\" role=\"presentation\"><ag-input-text-field ref=\"eFloatingFilterText\"></ag-input-text-field></div>") || this; | ||
var _this = _super.call(this, /* html */ "\n <div class=\"ag-floating-filter-input\" role=\"presentation\">\n <ag-input-text-field ref=\"eFloatingFilterText\"></ag-input-text-field>\n </div>") || this; | ||
_this.availableValuesListenerAdded = false; | ||
@@ -35,5 +35,5 @@ return _this; | ||
// unlike other filters, what we show in the floating filter can be different, even | ||
// if another filter changes. this is due to how set filter restricts it's values based | ||
// on selections in other filters. eg if you filter Language to English, then the set filter | ||
// on Country will only show English speaking countries. thus the list of items to show | ||
// if another filter changes. this is due to how set filter restricts its values based | ||
// on selections in other filters, e.g. if you filter Language to English, then the set filter | ||
// on Country will only show English speaking countries. Thus the list of items to show | ||
// in the floating filter can change. | ||
@@ -51,3 +51,3 @@ SetFloatingFilterComp.prototype.onAvailableValuesChanged = function (filterChangedEvent) { | ||
var setValueModel = setFilter.getValueModel(); | ||
_this.addDestroyableEventListener(setValueModel, SetValueModel.EVENT_AVAILABLE_VALUES_CHANGES, _this.onAvailableValuesChanged.bind(_this)); | ||
_this.addDestroyableEventListener(setValueModel, SetValueModel.EVENT_AVAILABLE_VALUES_CHANGED, _this.onAvailableValuesChanged.bind(_this)); | ||
}); | ||
@@ -66,3 +66,3 @@ this.availableValuesListenerAdded = true; | ||
// also supporting old filter model for backwards compatibility | ||
var values = (this.lastKnownModel instanceof Array) ? this.lastKnownModel : this.lastKnownModel.values; | ||
var values = this.lastKnownModel instanceof Array ? this.lastKnownModel : this.lastKnownModel.values; | ||
if (!values || values.length === 0) { | ||
@@ -74,5 +74,5 @@ this.eFloatingFilterText.setValue(''); | ||
var valueModel = setFilter.getValueModel(); | ||
var availableValues = values.filter(valueModel.isValueAvailable.bind(valueModel)); | ||
var availableValues = _.filter(values, function (v) { return valueModel.isValueAvailable(v); }); | ||
// format all the values, if a formatter is provided | ||
var formattedValues = availableValues.map(function (value) { | ||
var formattedValues = _.map(availableValues, function (value) { | ||
var formattedValue = _this.valueFormatterService.formatValue(_this.params.column, null, null, value); | ||
@@ -82,3 +82,3 @@ return formattedValue != null ? formattedValue : value; | ||
var arrayToDisplay = formattedValues.length > 10 ? formattedValues.slice(0, 10).concat('...') : formattedValues; | ||
var valuesString = "(" + formattedValues.length + ") " + arrayToDisplay.join(","); | ||
var valuesString = "(" + formattedValues.length + ") " + arrayToDisplay.join(','); | ||
_this.eFloatingFilterText.setValue(valuesString); | ||
@@ -85,0 +85,0 @@ }); |
@@ -1,74 +0,77 @@ | ||
import { ColDef, Column, IRowModel, ValueFormatterService, IEventEmitter } from "@ag-grid-community/core"; | ||
import { ColDef, Column, IRowModel, ValueFormatterService, IEventEmitter, RowNode } from '@ag-grid-community/core'; | ||
export declare enum SetFilterModelValuesType { | ||
PROVIDED_LIST = 0, | ||
PROVIDED_CB = 1, | ||
NOT_PROVIDED = 2 | ||
PROVIDED_CALLBACK = 1, | ||
TAKEN_FROM_GRID_VALUES = 2 | ||
} | ||
export declare class SetValueModel implements IEventEmitter { | ||
static EVENT_AVAILABLE_VALUES_CHANGES: string; | ||
private colDef; | ||
private filterParams; | ||
private clientSideRowModel; | ||
private valueGetter; | ||
private allUniqueValues; | ||
private availableUniqueValues; | ||
private availableUniqueValuesMap; | ||
private readonly colDef; | ||
private readonly valueGetter; | ||
private readonly doesRowPassOtherFilters; | ||
private readonly suppressSorting; | ||
private readonly setIsLoading; | ||
private readonly valueFormatterService; | ||
private readonly column; | ||
static EVENT_AVAILABLE_VALUES_CHANGED: string; | ||
private readonly localEventService; | ||
private readonly filterParams; | ||
private readonly clientSideRowModel; | ||
private readonly formatter; | ||
private valuesType; | ||
private miniFilterText; | ||
/** Values provided to the filter for use. */ | ||
private providedValues; | ||
/** Values can be loaded asynchronously, so wait on this promise if you need to ensure values have been loaded. */ | ||
private allValuesPromise; | ||
/** All possible values for the filter, sorted if required. */ | ||
private allValues; | ||
/** Remaining values when filters from other columns have been applied. */ | ||
private availableValues; | ||
/** All values that are currently displayed, after the mini-filter has been applied. */ | ||
private displayedValues; | ||
private miniFilter; | ||
private selectedValuesCount; | ||
private selectedValuesMap; | ||
private suppressSorting; | ||
private formatter; | ||
private showingAvailableOnly; | ||
private valuesType; | ||
private doesRowPassOtherFilters; | ||
private modelUpdatedFunc; | ||
private isLoadingFunc; | ||
private filterValuesExternalPromise; | ||
private filterValuesPromise; | ||
private valueFormatterService; | ||
private column; | ||
private localEventService; | ||
constructor(colDef: ColDef, rowModel: IRowModel, valueGetter: any, doesRowPassOtherFilters: any, suppressSorting: boolean, modelUpdatedFunc: (values: string[] | null, selected?: string[] | null) => void, isLoadingFunc: (loading: boolean) => void, valueFormatterService: ValueFormatterService, column: Column); | ||
/** Values that have been selected for this filter. */ | ||
private selectedValues; | ||
constructor(colDef: ColDef, rowModel: IRowModel, valueGetter: (node: RowNode) => any, doesRowPassOtherFilters: (node: RowNode) => boolean, suppressSorting: boolean, setIsLoading: (loading: boolean) => void, valueFormatterService: ValueFormatterService, column: Column); | ||
addEventListener(eventType: string, listener: Function, async?: boolean): void; | ||
removeEventListener(eventType: string, listener: Function, async?: boolean): void; | ||
refreshAfterNewRowsLoaded(keepSelection: any, everythingSelected: boolean): void; | ||
refreshValues(valuesToUse: string[], keepSelection: any, isSelectAll: boolean): void; | ||
private refreshSelection; | ||
/** | ||
* Re-fetches the values used in the filter from the value source. | ||
* If keepSelection is false or selectAll is true, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
refetchValues(keepSelection?: boolean): void; | ||
/** | ||
* Overrides the current values being used for the set filter. | ||
* If keepSelection is false, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
overrideValues(valuesToUse: string[], keepSelection?: boolean): void; | ||
refreshAfterAnyFilterChanged(): void; | ||
private createAllUniqueValues; | ||
private onAsyncValuesLoaded; | ||
private areValuesSync; | ||
private updateAllValues; | ||
setValuesType(value: SetFilterModelValuesType): void; | ||
getValuesType(): SetFilterModelValuesType; | ||
private setValues; | ||
private extractSyncValuesToUse; | ||
isValueAvailable(value: string): boolean; | ||
private createAvailableUniqueValues; | ||
private showAvailableOnly; | ||
private updateAvailableValues; | ||
private sortValues; | ||
private getUniqueValues; | ||
setMiniFilter(newMiniFilter: string | null): boolean; | ||
private getValuesFromRows; | ||
/** Sets mini filter value. Returns true if it changed from last value, otherwise false. */ | ||
setMiniFilter(value?: string): boolean; | ||
getMiniFilter(): string; | ||
private processMiniFilter; | ||
private updateDisplayedValues; | ||
getDisplayedValueCount(): number; | ||
getDisplayedValue(index: any): any; | ||
selectAllUsingMiniFilter(): void; | ||
private selectOn; | ||
private valueToKey; | ||
private keyToValue; | ||
getDisplayedValue(index: any): string; | ||
isFilterActive(): boolean; | ||
selectNothingUsingMiniFilter(): void; | ||
private selectNothing; | ||
getUniqueValueCount(): number; | ||
getUniqueValue(index: any): string | null; | ||
unselectValue(value: any): void; | ||
selectAllFromMiniFilter(): void; | ||
selectValue(value: any): void; | ||
isValueSelected(value: any): boolean; | ||
selectAll(clearExistingSelection?: boolean): void; | ||
selectNothing(): void; | ||
selectValue(value: string): void; | ||
deselectValue(value: string): void; | ||
isValueSelected(value: string): boolean; | ||
isEverythingSelected(): boolean; | ||
isNothingSelected(): boolean; | ||
getModel(): string[] | null; | ||
setModel(model: string[] | null, isSelectAll?: boolean): void; | ||
private setSyncModel; | ||
onFilterValuesReady(callback: () => void): void; | ||
setModel(model: string[]): void; | ||
onFilterValuesReady(callback: (values: string[]) => void): void; | ||
} |
@@ -1,48 +0,50 @@ | ||
import { Constants, Promise, TextFilter, _, EventService } from "@ag-grid-community/core"; | ||
// we cannot have 'null' as a key in a JavaScript map, | ||
// it needs to be a string. so we use this string for | ||
// storing null values. | ||
var NULL_VALUE = '___NULL___'; | ||
import { Constants, Promise, TextFilter, _, EventService } from '@ag-grid-community/core'; | ||
export var SetFilterModelValuesType; | ||
(function (SetFilterModelValuesType) { | ||
SetFilterModelValuesType[SetFilterModelValuesType["PROVIDED_LIST"] = 0] = "PROVIDED_LIST"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["PROVIDED_CB"] = 1] = "PROVIDED_CB"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["NOT_PROVIDED"] = 2] = "NOT_PROVIDED"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["PROVIDED_CALLBACK"] = 1] = "PROVIDED_CALLBACK"; | ||
SetFilterModelValuesType[SetFilterModelValuesType["TAKEN_FROM_GRID_VALUES"] = 2] = "TAKEN_FROM_GRID_VALUES"; | ||
})(SetFilterModelValuesType || (SetFilterModelValuesType = {})); | ||
var SetValueModel = /** @class */ (function () { | ||
function SetValueModel(colDef, rowModel, valueGetter, doesRowPassOtherFilters, suppressSorting, modelUpdatedFunc, isLoadingFunc, valueFormatterService, column) { | ||
this.localEventService = new EventService(); | ||
this.suppressSorting = suppressSorting; | ||
function SetValueModel(colDef, rowModel, valueGetter, doesRowPassOtherFilters, suppressSorting, setIsLoading, valueFormatterService, column) { | ||
var _this = this; | ||
this.colDef = colDef; | ||
this.valueGetter = valueGetter; | ||
this.doesRowPassOtherFilters = doesRowPassOtherFilters; | ||
this.modelUpdatedFunc = modelUpdatedFunc; | ||
this.isLoadingFunc = isLoadingFunc; | ||
this.suppressSorting = suppressSorting; | ||
this.setIsLoading = setIsLoading; | ||
this.valueFormatterService = valueFormatterService; | ||
this.column = column; | ||
this.localEventService = new EventService(); | ||
this.miniFilterText = null; | ||
// The lookup for a set is much faster than the lookup for an array, especially when the length of the array is | ||
// thousands of records long, so where lookups are important we use a set. | ||
/** Values provided to the filter for use. */ | ||
this.providedValues = null; | ||
/** All possible values for the filter, sorted if required. */ | ||
this.allValues = []; | ||
/** Remaining values when filters from other columns have been applied. */ | ||
this.availableValues = new Set(); | ||
/** All values that are currently displayed, after the mini-filter has been applied. */ | ||
this.displayedValues = []; | ||
/** Values that have been selected for this filter. */ | ||
this.selectedValues = new Set(); | ||
if (rowModel.getType() === Constants.ROW_MODEL_TYPE_CLIENT_SIDE) { | ||
this.clientSideRowModel = rowModel; | ||
} | ||
this.filterParams = this.colDef.filterParams ? this.colDef.filterParams : {}; | ||
if (_.exists(this.filterParams) && _.exists(this.filterParams.values)) { | ||
this.valuesType = Array.isArray(this.filterParams.values) ? | ||
SetFilterModelValuesType.PROVIDED_LIST : | ||
SetFilterModelValuesType.PROVIDED_CB; | ||
this.showingAvailableOnly = this.filterParams.suppressRemoveEntries !== true; | ||
this.filterParams = this.colDef.filterParams || {}; | ||
this.formatter = this.filterParams.textFormatter || TextFilter.DEFAULT_FORMATTER; | ||
var values = this.filterParams.values; | ||
if (values == null) { | ||
this.valuesType = SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES; | ||
} | ||
else { | ||
this.valuesType = SetFilterModelValuesType.NOT_PROVIDED; | ||
this.showingAvailableOnly = true; | ||
this.valuesType = Array.isArray(values) ? | ||
SetFilterModelValuesType.PROVIDED_LIST : | ||
SetFilterModelValuesType.PROVIDED_CALLBACK; | ||
this.providedValues = values; | ||
} | ||
this.createAllUniqueValues(); | ||
this.createAvailableUniqueValues(); | ||
// by default, no filter, so we display everything | ||
this.displayedValues = this.availableUniqueValues; | ||
this.miniFilter = null; | ||
// we use a map rather than an array for the selected values as the lookup | ||
// for a map is much faster than the lookup for an array, especially when | ||
// the length of the array is thousands of records long | ||
this.selectNothing(); | ||
this.selectAllUsingMiniFilter(); | ||
this.formatter = this.filterParams.textFormatter ? this.filterParams.textFormatter : TextFilter.DEFAULT_FORMATTER; | ||
this.updateAllValues(); | ||
// start with everything selected | ||
this.allValuesPromise.then(function (values) { return _this.selectedValues = _.convertToSet(values); }); | ||
} | ||
@@ -55,61 +57,72 @@ SetValueModel.prototype.addEventListener = function (eventType, listener, async) { | ||
}; | ||
// if keepSelection not set will always select all filters | ||
// if keepSelection set will keep current state of selected filters | ||
// unless selectAll chosen in which case will select all | ||
SetValueModel.prototype.refreshAfterNewRowsLoaded = function (keepSelection, everythingSelected) { | ||
this.createAllUniqueValues(); | ||
this.refreshSelection(keepSelection, everythingSelected); | ||
/** | ||
* Re-fetches the values used in the filter from the value source. | ||
* If keepSelection is false or selectAll is true, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
SetValueModel.prototype.refetchValues = function (keepSelection) { | ||
var _this = this; | ||
if (keepSelection === void 0) { keepSelection = true; } | ||
var currentModel = this.getModel(); | ||
this.updateAllValues(); | ||
// ensure model is updated for new values | ||
this.allValuesPromise.then(function () { return _this.setModel(keepSelection ? currentModel : null); }); | ||
}; | ||
// if keepSelection not set will always select all filters | ||
// if keepSelection set will keep current state of selected filters | ||
// unless selectAll chosen in which case will select all | ||
SetValueModel.prototype.refreshValues = function (valuesToUse, keepSelection, isSelectAll) { | ||
this.setValues(valuesToUse); | ||
this.refreshSelection(keepSelection, isSelectAll); | ||
/** | ||
* Overrides the current values being used for the set filter. | ||
* If keepSelection is false, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
SetValueModel.prototype.overrideValues = function (valuesToUse, keepSelection) { | ||
var _this = this; | ||
if (keepSelection === void 0) { keepSelection = true; } | ||
// wait for any existing values to be populated before overriding | ||
this.allValuesPromise.then(function () { | ||
_this.valuesType = SetFilterModelValuesType.PROVIDED_LIST; | ||
_this.providedValues = valuesToUse; | ||
_this.refetchValues(keepSelection); | ||
}); | ||
}; | ||
SetValueModel.prototype.refreshSelection = function (keepSelection, isSelectAll) { | ||
this.createAvailableUniqueValues(); | ||
var oldModel = Object.keys(this.selectedValuesMap); | ||
this.selectNothing(); | ||
this.processMiniFilter(); | ||
if (keepSelection) { | ||
this.setModel(oldModel, isSelectAll); | ||
} | ||
else { | ||
this.selectAllUsingMiniFilter(); | ||
} | ||
}; | ||
SetValueModel.prototype.refreshAfterAnyFilterChanged = function () { | ||
if (this.showingAvailableOnly) { | ||
this.createAvailableUniqueValues(); | ||
this.processMiniFilter(); | ||
if (this.showAvailableOnly()) { | ||
this.updateAvailableValues(); | ||
} | ||
}; | ||
SetValueModel.prototype.createAllUniqueValues = function () { | ||
if (this.areValuesSync()) { | ||
var valuesToUse = this.extractSyncValuesToUse(); | ||
this.setValues(valuesToUse); | ||
this.filterValuesPromise = Promise.resolve([]); | ||
SetValueModel.prototype.updateAllValues = function () { | ||
var _this = this; | ||
switch (this.valuesType) { | ||
case SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES: | ||
case SetFilterModelValuesType.PROVIDED_LIST: { | ||
var values = this.valuesType === SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES ? | ||
this.getValuesFromRows(false) : _.toStrings(this.providedValues); | ||
var sortedValues = this.sortValues(values); | ||
this.allValues = sortedValues; | ||
this.allValuesPromise = Promise.resolve(sortedValues); | ||
break; | ||
} | ||
case SetFilterModelValuesType.PROVIDED_CALLBACK: { | ||
this.setIsLoading(true); | ||
this.allValuesPromise = new Promise(function (resolve) { | ||
var callback = _this.providedValues; | ||
var params = { | ||
success: function (values) { | ||
var processedValues = _.toStrings(values); | ||
_this.setIsLoading(false); | ||
_this.valuesType = SetFilterModelValuesType.PROVIDED_LIST; | ||
_this.providedValues = processedValues; | ||
var sortedValues = _this.sortValues(processedValues); | ||
_this.allValues = sortedValues; | ||
resolve(sortedValues); | ||
}, | ||
colDef: _this.colDef | ||
}; | ||
window.setTimeout(function () { return callback(params); }, 0); | ||
}); | ||
break; | ||
} | ||
default: | ||
throw new Error('Unrecognised valuesType'); | ||
} | ||
else { | ||
this.filterValuesExternalPromise = Promise.external(); | ||
this.filterValuesPromise = this.filterValuesExternalPromise.promise; | ||
this.isLoadingFunc(true); | ||
this.setValues([]); | ||
var callback_1 = this.filterParams.values; | ||
var params_1 = { | ||
success: this.onAsyncValuesLoaded.bind(this), | ||
colDef: this.colDef | ||
}; | ||
window.setTimeout(function () { return callback_1(params_1); }, 0); | ||
} | ||
this.updateAvailableValues(); | ||
}; | ||
SetValueModel.prototype.onAsyncValuesLoaded = function (values) { | ||
this.modelUpdatedFunc(values); | ||
this.isLoadingFunc(false); | ||
this.filterValuesExternalPromise.resolve(values); | ||
}; | ||
SetValueModel.prototype.areValuesSync = function () { | ||
return this.valuesType == SetFilterModelValuesType.PROVIDED_LIST || this.valuesType == SetFilterModelValuesType.NOT_PROVIDED; | ||
}; | ||
SetValueModel.prototype.setValuesType = function (value) { | ||
@@ -121,63 +134,30 @@ this.valuesType = value; | ||
}; | ||
SetValueModel.prototype.setValues = function (valuesToUse) { | ||
this.allUniqueValues = valuesToUse; | ||
if (!this.suppressSorting) { | ||
this.sortValues(this.allUniqueValues); | ||
} | ||
SetValueModel.prototype.isValueAvailable = function (value) { | ||
return this.availableValues.has(value); | ||
}; | ||
SetValueModel.prototype.extractSyncValuesToUse = function () { | ||
var valuesToUse; | ||
if (this.valuesType == SetFilterModelValuesType.PROVIDED_LIST) { | ||
if (Array.isArray(this.filterParams.values)) { | ||
valuesToUse = _.toStrings(this.filterParams.values); | ||
} | ||
else { | ||
// In this case the values are async but have already been resolved, so we can reuse them | ||
valuesToUse = this.allUniqueValues; | ||
} | ||
} | ||
else if (this.valuesType == SetFilterModelValuesType.PROVIDED_CB) { | ||
throw Error("ag-grid: Error extracting values to use. We should not extract the values synchronously when using a callback for the filterParams.values"); | ||
} | ||
else { | ||
var uniqueValuesAsAnyObjects = this.getUniqueValues(false); | ||
valuesToUse = _.toStrings(uniqueValuesAsAnyObjects); | ||
} | ||
return valuesToUse; | ||
SetValueModel.prototype.showAvailableOnly = function () { | ||
return this.valuesType === SetFilterModelValuesType.TAKEN_FROM_GRID_VALUES && | ||
!this.filterParams.suppressRemoveEntries; | ||
}; | ||
SetValueModel.prototype.isValueAvailable = function (value) { | ||
return this.availableUniqueValuesMap[value]; | ||
}; | ||
SetValueModel.prototype.createAvailableUniqueValues = function () { | ||
SetValueModel.prototype.updateAvailableValues = function () { | ||
var _this = this; | ||
var dontCheckAvailableValues = !this.showingAvailableOnly || this.valuesType == SetFilterModelValuesType.PROVIDED_LIST || this.valuesType == SetFilterModelValuesType.PROVIDED_CB; | ||
if (dontCheckAvailableValues) { | ||
this.availableUniqueValues = this.allUniqueValues; | ||
} | ||
else { | ||
var uniqueValuesAsAnyObjects = this.getUniqueValues(true); | ||
this.availableUniqueValues = _.toStrings(uniqueValuesAsAnyObjects); | ||
this.sortValues(this.availableUniqueValues); | ||
} | ||
this.availableUniqueValuesMap = {}; | ||
if (this.availableUniqueValues) { | ||
this.availableUniqueValues.forEach(function (value) { return _this.availableUniqueValuesMap[value] = true; }); | ||
} | ||
this.localEventService.dispatchEvent({ type: SetValueModel.EVENT_AVAILABLE_VALUES_CHANGES }); | ||
this.allValuesPromise.then(function (values) { | ||
var availableValues = _this.showAvailableOnly() ? _this.sortValues(_this.getValuesFromRows(true)) : values; | ||
_this.availableValues = _.convertToSet(availableValues); | ||
_this.localEventService.dispatchEvent({ type: SetValueModel.EVENT_AVAILABLE_VALUES_CHANGED }); | ||
_this.updateDisplayedValues(); | ||
}); | ||
}; | ||
SetValueModel.prototype.sortValues = function (values) { | ||
if (this.filterParams && this.filterParams.comparator) { | ||
values.sort(this.filterParams.comparator); | ||
if (this.suppressSorting) { | ||
return values; | ||
} | ||
else if (this.colDef.comparator) { | ||
values.sort(this.colDef.comparator); | ||
} | ||
else { | ||
values.sort(_.defaultComparator); | ||
} | ||
var comparator = this.filterParams.comparator || | ||
this.colDef.comparator || | ||
_.defaultComparator; | ||
return values.sort(comparator); | ||
}; | ||
SetValueModel.prototype.getUniqueValues = function (filterOutNotAvailable) { | ||
SetValueModel.prototype.getValuesFromRows = function (removeUnavailableValues) { | ||
var _this = this; | ||
var uniqueCheck = {}; | ||
var result = []; | ||
if (removeUnavailableValues === void 0) { removeUnavailableValues = false; } | ||
if (!this.clientSideRowModel) { | ||
@@ -187,54 +167,45 @@ console.error('ag-Grid: Set Filter cannot initialise because you are using a row model that does not contain all rows in the browser. Either use a different filter type, or configure Set Filter such that you provide it with values'); | ||
} | ||
var values = new Set(); | ||
var keyCreator = this.colDef.keyCreator; | ||
this.clientSideRowModel.forEachLeafNode(function (node) { | ||
// only pull values from rows that have data. this means we skip filler group nodes. | ||
if (!node.data) { | ||
if (!node.data || (removeUnavailableValues && !_this.doesRowPassOtherFilters(node))) { | ||
return; | ||
} | ||
var value = _this.valueGetter(node); | ||
if (_this.colDef.keyCreator) { | ||
value = _this.colDef.keyCreator({ value: value }); | ||
if (keyCreator) { | ||
value = keyCreator({ value: value }); | ||
} | ||
if (value === "" || value === undefined) { | ||
value = null; | ||
} | ||
if (filterOutNotAvailable) { | ||
if (!_this.doesRowPassOtherFilters(node)) { | ||
return; | ||
} | ||
} | ||
value = _.makeNull(value); | ||
if (value != null && Array.isArray(value)) { | ||
for (var j = 0; j < value.length; j++) { | ||
addUniqueValueIfMissing(value[j]); | ||
} | ||
_.forEach(value, function (x) { | ||
var formatted = _.toStringOrNull(_.makeNull(x)); | ||
values.add(formatted); | ||
}); | ||
} | ||
else { | ||
addUniqueValueIfMissing(value); | ||
values.add(_.toStringOrNull(value)); | ||
} | ||
}); | ||
function addUniqueValueIfMissing(value) { | ||
if (!uniqueCheck.hasOwnProperty(value)) { | ||
result.push(value); | ||
uniqueCheck[value] = 1; | ||
} | ||
} | ||
return result; | ||
return _.values(values); | ||
}; | ||
//sets mini filter. returns true if it changed from last value, otherwise false | ||
SetValueModel.prototype.setMiniFilter = function (newMiniFilter) { | ||
newMiniFilter = _.makeNull(newMiniFilter); | ||
if (this.miniFilter === newMiniFilter) { | ||
/** Sets mini filter value. Returns true if it changed from last value, otherwise false. */ | ||
SetValueModel.prototype.setMiniFilter = function (value) { | ||
value = _.makeNull(value); | ||
if (this.miniFilterText === value) { | ||
//do nothing if filter has not changed | ||
return false; | ||
} | ||
this.miniFilter = newMiniFilter; | ||
this.processMiniFilter(); | ||
this.miniFilterText = value; | ||
this.updateDisplayedValues(); | ||
return true; | ||
}; | ||
SetValueModel.prototype.getMiniFilter = function () { | ||
return this.miniFilter; | ||
return this.miniFilterText; | ||
}; | ||
SetValueModel.prototype.processMiniFilter = function () { | ||
// if no filter, just use the unique values | ||
if (this.miniFilter === null) { | ||
this.displayedValues = this.availableUniqueValues; | ||
SetValueModel.prototype.updateDisplayedValues = function () { | ||
var _this = this; | ||
// if no filter, just display all available values | ||
if (this.miniFilterText == null) { | ||
this.displayedValues = _.values(this.availableValues); | ||
return; | ||
@@ -244,24 +215,17 @@ } | ||
this.displayedValues = []; | ||
var miniFilter = this.formatter(this.miniFilter); | ||
// make upper case to have search case insensitive | ||
var miniFilterUpperCase = miniFilter.toUpperCase(); | ||
//This function encapsulates the logic to check if a string matches the mini filter | ||
var matchesFn = function (valueToCheck) { | ||
if (valueToCheck == null) { | ||
return false; | ||
} | ||
// allow for case insensitive searches, make both filter and value uppercase | ||
var valueUpperCase = valueToCheck.toUpperCase(); | ||
return valueUpperCase.indexOf(miniFilterUpperCase) >= 0; | ||
// to allow for case insensitive searches, upper-case both filter text and value | ||
var formattedFilterText = this.formatter(this.miniFilterText).toUpperCase(); | ||
var matchesFilter = function (valueToCheck) { | ||
return valueToCheck != null && valueToCheck.toUpperCase().indexOf(formattedFilterText) >= 0; | ||
}; | ||
for (var i = 0, l = this.availableUniqueValues.length; i < l; i++) { | ||
var value = this.availableUniqueValues[i]; | ||
if (value) { | ||
var displayedValue = this.formatter(value.toString()); | ||
var formattedValue = this.valueFormatterService.formatValue(this.column, null, null, displayedValue); | ||
if (matchesFn(displayedValue) || matchesFn(formattedValue)) { | ||
this.displayedValues.push(value); | ||
} | ||
this.availableValues.forEach(function (value) { | ||
if (value == null) { | ||
return; | ||
} | ||
} | ||
var displayedValue = _this.formatter(value); | ||
var formattedValue = _this.valueFormatterService.formatValue(_this.column, null, null, displayedValue); | ||
if (matchesFilter(displayedValue) || matchesFilter(formattedValue)) { | ||
_this.displayedValues.push(value); | ||
} | ||
}); | ||
}; | ||
@@ -274,86 +238,53 @@ SetValueModel.prototype.getDisplayedValueCount = function () { | ||
}; | ||
SetValueModel.prototype.selectAllUsingMiniFilter = function () { | ||
if (this.miniFilter) { | ||
this.selectOn(this.displayedValues); | ||
} | ||
else { | ||
this.selectOn(this.allUniqueValues); | ||
} | ||
SetValueModel.prototype.isFilterActive = function () { | ||
return this.allValues.length !== this.selectedValues.size; | ||
}; | ||
SetValueModel.prototype.selectOn = function (toSelectOn) { | ||
var count = toSelectOn.length; | ||
for (var i = 0; i < count; i++) { | ||
var key = toSelectOn[i]; | ||
var safeKey = this.valueToKey(key); | ||
this.selectedValuesMap[safeKey] = null; | ||
} | ||
this.selectedValuesCount = Object.keys(this.selectedValuesMap).length; | ||
SetValueModel.prototype.getUniqueValueCount = function () { | ||
return this.allValues.length; | ||
}; | ||
SetValueModel.prototype.valueToKey = function (key) { | ||
if (key === null) { | ||
return NULL_VALUE; | ||
} | ||
else { | ||
return key; | ||
} | ||
SetValueModel.prototype.getUniqueValue = function (index) { | ||
return this.allValues[index]; | ||
}; | ||
SetValueModel.prototype.keyToValue = function (value) { | ||
if (value === NULL_VALUE) { | ||
return null; | ||
SetValueModel.prototype.selectAll = function (clearExistingSelection) { | ||
var _this = this; | ||
if (clearExistingSelection === void 0) { clearExistingSelection = false; } | ||
if (this.miniFilterText == null) { | ||
// ensure everything is selected | ||
this.selectedValues = _.convertToSet(this.allValues); | ||
} | ||
else { | ||
return value; | ||
// ensure everything that matches the mini filter is selected | ||
if (clearExistingSelection) { | ||
this.selectedValues.clear(); | ||
} | ||
_.forEach(this.displayedValues, function (value) { return _this.selectValue(value); }); | ||
} | ||
}; | ||
SetValueModel.prototype.isFilterActive = function () { | ||
return this.allUniqueValues.length !== this.selectedValuesCount; | ||
}; | ||
SetValueModel.prototype.selectNothingUsingMiniFilter = function () { | ||
SetValueModel.prototype.selectNothing = function () { | ||
var _this = this; | ||
if (this.miniFilter) { | ||
this.displayedValues.forEach(function (it) { return _this.unselectValue(it); }); | ||
if (this.miniFilterText == null) { | ||
// ensure everything is deselected | ||
this.selectedValues.clear(); | ||
} | ||
else { | ||
this.selectNothing(); | ||
// ensure everything that matches the mini filter is deselected | ||
_.forEach(this.displayedValues, function (it) { return _this.deselectValue(it); }); | ||
} | ||
}; | ||
SetValueModel.prototype.selectNothing = function () { | ||
this.selectedValuesMap = {}; | ||
this.selectedValuesCount = 0; | ||
SetValueModel.prototype.selectValue = function (value) { | ||
this.selectedValues.add(value); | ||
}; | ||
SetValueModel.prototype.getUniqueValueCount = function () { | ||
return this.allUniqueValues.length; | ||
SetValueModel.prototype.deselectValue = function (value) { | ||
this.selectedValues.delete(value); | ||
}; | ||
SetValueModel.prototype.getUniqueValue = function (index) { | ||
return this.allUniqueValues[index]; | ||
}; | ||
SetValueModel.prototype.unselectValue = function (value) { | ||
var safeKey = this.valueToKey(value); | ||
if (this.selectedValuesMap[safeKey] !== undefined) { | ||
delete this.selectedValuesMap[safeKey]; | ||
this.selectedValuesCount--; | ||
} | ||
}; | ||
SetValueModel.prototype.selectAllFromMiniFilter = function () { | ||
this.selectNothing(); | ||
this.selectAllUsingMiniFilter(); | ||
}; | ||
SetValueModel.prototype.selectValue = function (value) { | ||
var safeKey = this.valueToKey(value); | ||
if (this.selectedValuesMap[safeKey] === undefined) { | ||
this.selectedValuesMap[safeKey] = null; | ||
this.selectedValuesCount++; | ||
} | ||
}; | ||
SetValueModel.prototype.isValueSelected = function (value) { | ||
var safeKey = this.valueToKey(value); | ||
return this.selectedValuesMap[safeKey] !== undefined; | ||
return this.selectedValues.has(value); | ||
}; | ||
SetValueModel.prototype.isEverythingSelected = function () { | ||
var _this = this; | ||
if (this.miniFilter) { | ||
return this.displayedValues.filter(function (it) { return _this.isValueSelected(it); }).length === this.displayedValues.length; | ||
if (this.miniFilterText == null) { | ||
return this.allValues.length === this.selectedValues.size; | ||
} | ||
else { | ||
return this.allUniqueValues.length === this.selectedValuesCount; | ||
return _.filter(this.displayedValues, function (it) { return _this.isValueSelected(it); }).length === this.displayedValues.length; | ||
} | ||
@@ -363,61 +294,37 @@ }; | ||
var _this = this; | ||
if (this.miniFilter) { | ||
return this.displayedValues.filter(function (it) { return _this.isValueSelected(it); }).length === 0; | ||
if (this.miniFilterText == null) { | ||
return this.selectedValues.size === 0; | ||
} | ||
else { | ||
return this.selectedValuesCount === 0; | ||
return _.filter(this.displayedValues, function (it) { return _this.isValueSelected(it); }).length === 0; | ||
} | ||
}; | ||
SetValueModel.prototype.getModel = function () { | ||
var _this = this; | ||
if (!this.isFilterActive()) { | ||
return null; | ||
} | ||
var selectedValues = []; | ||
_.iterateObject(this.selectedValuesMap, function (key) { | ||
var value = _this.keyToValue(key); | ||
selectedValues.push(value); | ||
}); | ||
return selectedValues; | ||
return this.isFilterActive() ? _.values(this.selectedValues) : null; | ||
}; | ||
SetValueModel.prototype.setModel = function (model, isSelectAll) { | ||
SetValueModel.prototype.setModel = function (model) { | ||
var _this = this; | ||
if (isSelectAll === void 0) { isSelectAll = false; } | ||
if (this.areValuesSync()) { | ||
this.setSyncModel(model, isSelectAll); | ||
} | ||
else { | ||
this.filterValuesExternalPromise.promise.then(function (values) { | ||
_this.setSyncModel(model, isSelectAll); | ||
_this.modelUpdatedFunc(values, model); | ||
}); | ||
} | ||
}; | ||
SetValueModel.prototype.setSyncModel = function (model, isSelectAll) { | ||
if (isSelectAll === void 0) { isSelectAll = false; } | ||
if (model && !isSelectAll) { | ||
this.selectNothingUsingMiniFilter(); | ||
for (var i = 0; i < model.length; i++) { | ||
var rawValue = model[i]; | ||
var value = this.keyToValue(rawValue); | ||
if (this.allUniqueValues.indexOf(value) >= 0) { | ||
this.selectValue(value); | ||
} | ||
this.allValuesPromise.then(function (values) { | ||
if (model == null) { | ||
// reset to everything selected | ||
_this.selectedValues = _.convertToSet(values); | ||
} | ||
} | ||
else { | ||
this.selectAllUsingMiniFilter(); | ||
} | ||
else { | ||
// select all values from the model that exist in the filter | ||
_this.selectedValues.clear(); | ||
var allValues_1 = _.convertToSet(values); | ||
_.forEach(model, function (value) { | ||
if (allValues_1.has(value)) { | ||
_this.selectValue(value); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
SetValueModel.prototype.onFilterValuesReady = function (callback) { | ||
//This guarantees that if the user is racing to set values async into the set filter, only the first instance | ||
//will be used | ||
// ie Values are async and the user manually wants to override them before the retrieval of values is triggered | ||
// (set filter values in the following example) | ||
// http://plnkr.co/edit/eFka7ynvPj68tL3VJFWf?p=preview | ||
this.filterValuesPromise.firstOneOnly(callback); | ||
this.allValuesPromise.then(callback); | ||
}; | ||
SetValueModel.EVENT_AVAILABLE_VALUES_CHANGES = 'availableValuesChanged'; | ||
SetValueModel.EVENT_AVAILABLE_VALUES_CHANGED = 'availableValuesChanged'; | ||
return SetValueModel; | ||
}()); | ||
export { SetValueModel }; |
@@ -1,2 +0,2 @@ | ||
import { Module } from "@ag-grid-community/core"; | ||
import { Module } from '@ag-grid-community/core'; | ||
export declare const SetFilterModule: Module; |
@@ -1,5 +0,5 @@ | ||
import { ModuleNames } from "@ag-grid-community/core"; | ||
import { EnterpriseCoreModule } from "@ag-grid-enterprise/core"; | ||
import { SetFilter } from "./setFilter/setFilter"; | ||
import { SetFloatingFilterComp } from "./setFilter/setFloatingFilter"; | ||
import { ModuleNames } from '@ag-grid-community/core'; | ||
import { EnterpriseCoreModule } from '@ag-grid-enterprise/core'; | ||
import { SetFilter } from './setFilter/setFilter'; | ||
import { SetFloatingFilterComp } from './setFilter/setFloatingFilter'; | ||
export var SetFilterModule = { | ||
@@ -6,0 +6,0 @@ moduleName: ModuleNames.SetFilterModule, |
{ | ||
"name": "@ag-grid-enterprise/set-filter", | ||
"version": "23.0.2", | ||
"version": "23.1.0", | ||
"description": "Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components", | ||
@@ -12,3 +12,4 @@ "main": "./dist/cjs/main.js", | ||
"package": "node ../../module-build/rollup/build.js", | ||
"build": "npm run build-cjs && npm run build-es6 && tsc -p tsconfig.typings.json" | ||
"build": "npm run build-cjs && npm run build-es6 && tsc -p tsconfig.typings.json", | ||
"test": "jest" | ||
}, | ||
@@ -45,7 +46,10 @@ "repository": { | ||
"dependencies": { | ||
"@ag-grid-community/core": "~23.0.0", | ||
"@ag-grid-enterprise/core": "~23.0.0" | ||
"@ag-grid-community/core": "~23.1.0", | ||
"@ag-grid-enterprise/core": "~23.1.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^3.6.3" | ||
"@types/jest": "^25.2.1", | ||
"jest": "^25.4.0", | ||
"ts-jest": "^25.4.0", | ||
"typescript": "~3.6.5" | ||
}, | ||
@@ -52,0 +56,0 @@ "publishConfig": { |
@@ -1,2 +0,2 @@ | ||
export { SetFilterModule } from "./setFilterModule"; | ||
export { SetFilter } from "./setFilter/setFilter"; | ||
export { SetFilterModule } from './setFilterModule'; | ||
export { SetFilter } from './setFilter/setFilter'; |
@@ -1,8 +0,7 @@ | ||
import { IDoesFilterPassParams, ISetFilterParams, ProvidedFilter } from "@ag-grid-community/core"; | ||
import { SetValueModel } from "./setValueModel"; | ||
import { SetFilterModel } from "./setFilterModel"; | ||
import { IDoesFilterPassParams, ISetFilterParams, ProvidedFilter, IAfterGuiAttachedParams } from '@ag-grid-community/core'; | ||
import { SetValueModel } from './setValueModel'; | ||
import { SetFilterModel } from './setFilterModel'; | ||
export declare class SetFilter extends ProvidedFilter { | ||
private valueModel; | ||
private eSelectAll; | ||
private eSelectAllContainer; | ||
private eMiniFilter; | ||
@@ -12,6 +11,6 @@ private eFilterLoading; | ||
private eventService; | ||
private selectAllState; | ||
private selectAllState?; | ||
private setFilterParams; | ||
private virtualList; | ||
private appliedModelValuesMapped; | ||
private appliedModelValues; | ||
protected updateUiVisibility(): void; | ||
@@ -27,10 +26,13 @@ protected createBodyTemplate(): string; | ||
private checkSetFilterDeprecatedParams; | ||
private addEventListenersForDataChanges; | ||
/** Called when the data in the grid changes, to prompt the set filter values to be updated. */ | ||
private syncValuesAfterDataChange; | ||
private setupSyncValuesAfterDataChange; | ||
private updateCheckboxIcon; | ||
setLoading(loading: boolean): void; | ||
private initialiseFilterBodyUi; | ||
private initVirtualList; | ||
private createSetListItem; | ||
afterGuiAttached(params: any): void; | ||
refreshVirtualList(): void; | ||
private initMiniFilter; | ||
private initSelectAll; | ||
afterGuiAttached(params: IAfterGuiAttachedParams): void; | ||
applyModel(): boolean; | ||
@@ -47,6 +49,5 @@ doesFilterPass(params: IDoesFilterPassParams): boolean; | ||
*/ | ||
setFilterValues(options: string[], selectAll?: boolean, notify?: boolean, toSelect?: string[]): void; | ||
setFilterValues(options: string[]): void; | ||
/** | ||
* Public method provided so the user can reset the values of the filter once that it has started | ||
* @param options The options to use. | ||
* Public method provided so the user can reset the values of the filter once that it has started. | ||
*/ | ||
@@ -57,14 +58,13 @@ resetFilterValues(): void; | ||
private onMiniFilterKeyPress; | ||
private onEnterKeyOnMiniFilter; | ||
private onMiniFilterInput; | ||
private onSelectAll; | ||
private doSelectAll; | ||
private onItemSelected; | ||
setMiniFilter(newMiniFilter: any): void; | ||
setMiniFilter(newMiniFilter: string): void; | ||
getMiniFilter(): string; | ||
selectEverything(): void; | ||
selectNothing(): void; | ||
unselectValue(value: any): void; | ||
selectValue(value: any): void; | ||
isValueSelected(value: any): boolean; | ||
unselectValue(value: string): void; | ||
selectValue(value: string): void; | ||
private refresh; | ||
isValueSelected(value: string): boolean; | ||
isEverythingSelected(): boolean; | ||
@@ -74,2 +74,3 @@ isNothingSelected(): boolean; | ||
getUniqueValue(index: any): string; | ||
refreshVirtualList(): void; | ||
} |
@@ -1,5 +0,7 @@ | ||
import { AgEvent, Column, Component } from "@ag-grid-community/core"; | ||
import { AgEvent, ColDef, Component, ISetFilterParams } from '@ag-grid-community/core'; | ||
export interface SelectedEvent extends AgEvent { | ||
} | ||
export declare class SetFilterListItem extends Component { | ||
private readonly value; | ||
private readonly params; | ||
static EVENT_SELECTED: string; | ||
@@ -9,9 +11,8 @@ private gridOptionsWrapper; | ||
private userComponentFactory; | ||
private eFilterItemValue; | ||
private static TEMPLATE; | ||
private eCheckbox; | ||
private selected; | ||
private value; | ||
private column; | ||
constructor(value: any, column: Column); | ||
private useCellRenderer; | ||
private tooltipText; | ||
constructor(value: any, params: ISetFilterParams); | ||
private init; | ||
@@ -22,3 +23,6 @@ isSelected(): boolean; | ||
render(): void; | ||
private getFilterValueFormatter; | ||
private getFormattedValue; | ||
private renderCell; | ||
getComponentHolder(): ColDef; | ||
getTooltipText(): string; | ||
} |
@@ -1,4 +0,4 @@ | ||
import { ProvidedFilterModel } from "@ag-grid-community/core"; | ||
import { ProvidedFilterModel } from '@ag-grid-community/core'; | ||
export interface SetFilterModel extends ProvidedFilterModel { | ||
values: string[]; | ||
} |
@@ -1,3 +0,3 @@ | ||
import { FilterChangedEvent, Component, IFloatingFilter, IFloatingFilterParams } from "@ag-grid-community/core"; | ||
import { SetFilterModel } from "./setFilterModel"; | ||
import { FilterChangedEvent, Component, IFloatingFilter, IFloatingFilterParams } from '@ag-grid-community/core'; | ||
import { SetFilterModel } from './setFilterModel'; | ||
export declare class SetFloatingFilterComp extends Component implements IFloatingFilter { | ||
@@ -4,0 +4,0 @@ private eFloatingFilterText; |
@@ -1,74 +0,77 @@ | ||
import { ColDef, Column, IRowModel, ValueFormatterService, IEventEmitter } from "@ag-grid-community/core"; | ||
import { ColDef, Column, IRowModel, ValueFormatterService, IEventEmitter, RowNode } from '@ag-grid-community/core'; | ||
export declare enum SetFilterModelValuesType { | ||
PROVIDED_LIST = 0, | ||
PROVIDED_CB = 1, | ||
NOT_PROVIDED = 2 | ||
PROVIDED_CALLBACK = 1, | ||
TAKEN_FROM_GRID_VALUES = 2 | ||
} | ||
export declare class SetValueModel implements IEventEmitter { | ||
static EVENT_AVAILABLE_VALUES_CHANGES: string; | ||
private colDef; | ||
private filterParams; | ||
private clientSideRowModel; | ||
private valueGetter; | ||
private allUniqueValues; | ||
private availableUniqueValues; | ||
private availableUniqueValuesMap; | ||
private readonly colDef; | ||
private readonly valueGetter; | ||
private readonly doesRowPassOtherFilters; | ||
private readonly suppressSorting; | ||
private readonly setIsLoading; | ||
private readonly valueFormatterService; | ||
private readonly column; | ||
static EVENT_AVAILABLE_VALUES_CHANGED: string; | ||
private readonly localEventService; | ||
private readonly filterParams; | ||
private readonly clientSideRowModel; | ||
private readonly formatter; | ||
private valuesType; | ||
private miniFilterText; | ||
/** Values provided to the filter for use. */ | ||
private providedValues; | ||
/** Values can be loaded asynchronously, so wait on this promise if you need to ensure values have been loaded. */ | ||
private allValuesPromise; | ||
/** All possible values for the filter, sorted if required. */ | ||
private allValues; | ||
/** Remaining values when filters from other columns have been applied. */ | ||
private availableValues; | ||
/** All values that are currently displayed, after the mini-filter has been applied. */ | ||
private displayedValues; | ||
private miniFilter; | ||
private selectedValuesCount; | ||
private selectedValuesMap; | ||
private suppressSorting; | ||
private formatter; | ||
private showingAvailableOnly; | ||
private valuesType; | ||
private doesRowPassOtherFilters; | ||
private modelUpdatedFunc; | ||
private isLoadingFunc; | ||
private filterValuesExternalPromise; | ||
private filterValuesPromise; | ||
private valueFormatterService; | ||
private column; | ||
private localEventService; | ||
constructor(colDef: ColDef, rowModel: IRowModel, valueGetter: any, doesRowPassOtherFilters: any, suppressSorting: boolean, modelUpdatedFunc: (values: string[] | null, selected?: string[] | null) => void, isLoadingFunc: (loading: boolean) => void, valueFormatterService: ValueFormatterService, column: Column); | ||
/** Values that have been selected for this filter. */ | ||
private selectedValues; | ||
constructor(colDef: ColDef, rowModel: IRowModel, valueGetter: (node: RowNode) => any, doesRowPassOtherFilters: (node: RowNode) => boolean, suppressSorting: boolean, setIsLoading: (loading: boolean) => void, valueFormatterService: ValueFormatterService, column: Column); | ||
addEventListener(eventType: string, listener: Function, async?: boolean): void; | ||
removeEventListener(eventType: string, listener: Function, async?: boolean): void; | ||
refreshAfterNewRowsLoaded(keepSelection: any, everythingSelected: boolean): void; | ||
refreshValues(valuesToUse: string[], keepSelection: any, isSelectAll: boolean): void; | ||
private refreshSelection; | ||
/** | ||
* Re-fetches the values used in the filter from the value source. | ||
* If keepSelection is false or selectAll is true, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
refetchValues(keepSelection?: boolean): void; | ||
/** | ||
* Overrides the current values being used for the set filter. | ||
* If keepSelection is false, the filter selection will be reset to everything selected, | ||
* otherwise the current selection will be preserved. | ||
*/ | ||
overrideValues(valuesToUse: string[], keepSelection?: boolean): void; | ||
refreshAfterAnyFilterChanged(): void; | ||
private createAllUniqueValues; | ||
private onAsyncValuesLoaded; | ||
private areValuesSync; | ||
private updateAllValues; | ||
setValuesType(value: SetFilterModelValuesType): void; | ||
getValuesType(): SetFilterModelValuesType; | ||
private setValues; | ||
private extractSyncValuesToUse; | ||
isValueAvailable(value: string): boolean; | ||
private createAvailableUniqueValues; | ||
private showAvailableOnly; | ||
private updateAvailableValues; | ||
private sortValues; | ||
private getUniqueValues; | ||
setMiniFilter(newMiniFilter: string | null): boolean; | ||
private getValuesFromRows; | ||
/** Sets mini filter value. Returns true if it changed from last value, otherwise false. */ | ||
setMiniFilter(value?: string): boolean; | ||
getMiniFilter(): string; | ||
private processMiniFilter; | ||
private updateDisplayedValues; | ||
getDisplayedValueCount(): number; | ||
getDisplayedValue(index: any): any; | ||
selectAllUsingMiniFilter(): void; | ||
private selectOn; | ||
private valueToKey; | ||
private keyToValue; | ||
getDisplayedValue(index: any): string; | ||
isFilterActive(): boolean; | ||
selectNothingUsingMiniFilter(): void; | ||
private selectNothing; | ||
getUniqueValueCount(): number; | ||
getUniqueValue(index: any): string | null; | ||
unselectValue(value: any): void; | ||
selectAllFromMiniFilter(): void; | ||
selectValue(value: any): void; | ||
isValueSelected(value: any): boolean; | ||
selectAll(clearExistingSelection?: boolean): void; | ||
selectNothing(): void; | ||
selectValue(value: string): void; | ||
deselectValue(value: string): void; | ||
isValueSelected(value: string): boolean; | ||
isEverythingSelected(): boolean; | ||
isNothingSelected(): boolean; | ||
getModel(): string[] | null; | ||
setModel(model: string[] | null, isSelectAll?: boolean): void; | ||
private setSyncModel; | ||
onFilterValuesReady(callback: () => void): void; | ||
setModel(model: string[]): void; | ||
onFilterValuesReady(callback: (values: string[]) => void): void; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Module } from "@ag-grid-community/core"; | ||
import { Module } from '@ag-grid-community/core'; | ||
export declare const SetFilterModule: Module; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
5448948
59
86571
4
+ Added@ag-grid-community/core@23.1.1(transitive)
+ Added@ag-grid-enterprise/core@23.1.1(transitive)
- Removed@ag-grid-community/core@23.0.2(transitive)
- Removed@ag-grid-enterprise/core@23.0.2(transitive)