1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary DataGridDropDownFilter 5 */ 6 7 goog.provide('Banana.Controls.DataGridDropDownFilter'); 8 9 /** @namespace Banana.Controls.DataGridDropDownFilter */ 10 namespace('Banana.Controls').DataGridDropDownFilter = Banana.Controls.DropDown.extend( 11 /** @lends Banana.Controls.DataGridDropDownFilter.prototype */ 12 { 13 /** 14 * Creates a dropdown filter for usage in a datagrid 15 * @constructs 16 * @extends Banana.Controls.DropDown 17 */ 18 init : function() 19 { 20 this._super(); 21 22 this.allKey = '%'; 23 this.allTitle = null; 24 25 this.addCssClass("BDataGridFilter"); 26 27 // Needed for filter interface 28 this.bind('dataChanged',this.getProxy(function() { 29 this.triggerEvent('filterDataChanged'); 30 })); 31 this.bind('dataSourceChanged',this.getProxy(function() { 32 this.triggerEvent('filterDataSourceChanged'); 33 })); 34 }, 35 36 /** 37 * Sets datasource on the filter 38 * 39 * @param {Object} datasource 40 * @param {boolean} ignoreEvent 41 */ 42 setDataSource : function(datasource,ignoreEvent) 43 { 44 45 if (datasource instanceof Array && typeof(datasource[0]) == 'object') 46 { 47 var key = this.dataKeyField || 'key'; 48 var value = this.dataValueField || 'value' 49 50 var no = {}; 51 no[key] = this.allKey; 52 no[value] = this.allTitle || 'All '+this.filterField; 53 54 datasource.unshift(no); 55 } 56 else 57 { 58 var newds = {}; 59 newds[this.allKey] = this.allTitle || 'All '+this.filterField; 60 for (var prop in datasource) 61 { 62 if (typeof(datasource[prop]) == 'function') continue; 63 64 newds[datasource[prop]] = datasource[prop]; 65 } 66 datasource = newds; 67 } 68 69 this._super(datasource,ignoreEvent); 70 71 return this; 72 } 73 }); 74 75 Banana.Controls.DataGridDropDownFilter.prototype.getAllKey = function() 76 { 77 return this.allKey; 78 }; 79 80 Banana.Controls.DataGridDropDownFilter.prototype.setAllTitle = function(t,key) 81 { 82 this.allTitle = t; 83 84 if (key) 85 { 86 this.allKey = key; 87 } 88 89 return this; 90 }; 91 92 Banana.Controls.DataGridDropDownFilter.prototype.setFilterField = function(ff) 93 { 94 this.filterField = ff; 95 return this; 96 }; 97 98 Banana.Controls.DataGridDropDownFilter.prototype.setName = function(n) 99 { 100 this.name = n; 101 return this; 102 }; 103 104 Banana.Controls.DataGridDropDownFilter.prototype.getFilterfield = function() 105 { 106 return this.filterField; 107 }; 108 109 Banana.Controls.DataGridDropDownFilter.prototype.getData = function() 110 { 111 return this.data; 112 }; 113