Class Banana.Controls.DataGridFilterManager
Extends
Banana.Control.
- Methods borrowed from class Banana.Control:
- addControl, applyToChildren, bind, clear, createComponents, findControl, generateUniqueId, getClientId, getControls, getDomEventTypes, getFirstUiControl, getHtml, getId, getPage, getParent, getProxy, hasBind, invalidateDisplay, onPreInvalidateContents, onWindowResize, remove, render, setClientId, setId, setPage, setParent, triggerEvent, unbind, unload, updateDisplay
Defined in: DataGridFilterManager.js.
Creates a Filter Manager for usage in a datagrid. It centralize filter functionality of a datagrid by keeping track of filter changes and history. It saves data from the filters in the url and cookie.
Filters should be added by calling setFilters([]);
Filters should have an interface that at least contains:
function getAllKey(): returns the key that should be used when "all" is selected
Filters can trigger the following events:
- filterUrlChanged: triggered when url param of the filter is changed
- filterDataChanged: triggered when the filter data is changed
Example
var filterManager= new Banana.Controls.DataGridFilterManager();
filterManager.setUrlPreFix(pageId);
//everytime a filter changes, we come here. this could be the place to reload/update
//the data of the datagrid
filterManager.bind('filtersChanged',this.getProxy(function(e,filterData)
{
this.populateData(filterData);
}));
//assign some filters to the filterManager
filterManager.setFilters([
new Banana.Controls.DataGridDropDownFilter()
.setFilterField('type')
.setAllTitle('All Program types')
.dataSetSourceBind('programtypes','programtypes'),
new Banana.Controls.DataGridDropDownFilter()
.setFilterField('country')
.setAllTitle('All Series')
.dataSetSourceBind('programSeries','items'),
new Banana.Controls.DataGridCheckboxFilter()
.setFilterField('archive')
.setTitle('Display archived items'),
new Banana.Controls.DataGridSearchFilter()
.setFilterField('search'),
this.pagerFilter = new Banana.Controls.DataGridPagerFilter()
.setFilterField('pageIndex')
.dataSetSourceBind('dataset','pageCount')
.dataSetBind('dataset','pageIndex')
]);
//this is an array of filter controls. Just add them somewhere on your site.
//You can also add them in a DatagridControlPanel. It will automatically align them nicely.
var filters = filterManager.getFilters();
When invoked we will not try to restore filter states based on history
- Returns:
- {this}
Gets the current filter data each data part contains an object with - filterField name of the filter field - data the actual data - dataChanged boolean true when the filter is changed by the user
- Parameters:
- {boolean} ignoreCache
- when true we don't use the cache
- {boolean} flat
- when true we return key value array
- {boolean} ignoreNotVisible
- when true we don't include the invisble filters in the returned data
- Returns:
- {object} data of the filters
when called we do not auto adjust filter visibility. Normaly filters are hidden when no datasource is inside the filter.
- Returns:
- {this}
Set filters for this filtermanager. Each filter should extend from Banana.Controls.BaseDataGridFilter The data inside the filter can be set manually on each filter. If it is not manualy set we try to fetch it from the history. That means that if a user already used the filter or url param name we set that value back into the filter. Handy when user comes back to a page he already visited. The fiters will be restored to the old state. This restore operation can be avoided by called
- Parameters:
- {Array} filters
- the filters
- Returns:
- {this}
Filters can contain a so called all value. This value is used in cases where the user wants to unselect the filter. Normally we don't show this value in the url. This method will make that value visible. Useful when you need to know if a user selected the all value after coming from another page.
- Parameters:
- {Boolean} bool
- Returns:
- {this}