]>
Commit | Line | Data |
---|---|---|
947f0963 TL |
1 | /** |
2 | * This is the base class for {@link Ext.grid.Grid grid} cells that contain only text. | |
3 | * | |
4 | * {@link Ext.grid.Row Rows} create cells based on the {@link Ext.grid.column.Column#cell} | |
5 | * config. Application code would rarely create cells directly. | |
6 | */ | |
7 | Ext.define('Ext.grid.cell.Text', { | |
8 | extend: 'Ext.grid.cell.Base', | |
9 | xtype: 'textcell', | |
10 | ||
11 | config: { | |
12 | /** | |
13 | * @cfg {Boolean} encodeHtml | |
14 | * Specify `false` to write HTML directly to the cell. Be aware that doing this | |
15 | * can expose your application to security issues if that content is not known to | |
16 | * be safe. User input can contain malicious content such as `script` tags and | |
17 | * should be scrubbed before directly rendering that HTML. | |
18 | */ | |
19 | encodeHtml: true, | |
20 | ||
21 | /** | |
22 | * @cfg {String} rawValue | |
23 | * The text value of the cell. This value will be written to the cell differently | |
24 | * based on the {@link #encodeHtml} config. This config is automatically set as a | |
25 | * result of setting the {@link #value} config and is rarely set directly. This is | |
26 | * a separate config to avoid writting the same formatted result to the DOM. | |
27 | * @protected | |
28 | */ | |
29 | rawValue: null, | |
30 | ||
31 | /** | |
32 | * @cfg {String} zeroValue | |
33 | * | |
34 | * A replacement value for 0. | |
35 | * | |
36 | * If the cell value is 0 and you want to display it or hide it then you can define | |
37 | * a not null value here. | |
38 | * | |
39 | * Set it as an empty string if you want to hide cells that have 0s. | |
40 | */ | |
41 | zeroValue: null | |
42 | }, | |
43 | ||
44 | getTemplate: function() { | |
45 | var template = this.callParent(); | |
46 | ||
47 | template[0]["data-qoverflow"] = true; | |
48 | ||
49 | return template; | |
50 | }, | |
51 | ||
52 | formatValue: function(v) { | |
53 | var me = this, | |
54 | context = me.refreshContext, | |
55 | column = context.column, | |
56 | zeroValue = me.getZeroValue(), | |
57 | format = column.getFormatter(), | |
58 | renderer, scope; | |
59 | ||
60 | if (context.summary) { | |
61 | renderer = column.getSummaryRenderer(); | |
62 | ||
63 | if (renderer) { | |
64 | format = null; // ignore the non-summary formatter | |
65 | scope = context.scope; | |
66 | ||
67 | if (typeof renderer === 'string') { | |
68 | v = Ext.callback(renderer, scope, [ v, context ], 0, column); | |
69 | } | |
70 | else { | |
71 | v = renderer.call(scope || me, v, context); | |
72 | } | |
73 | } | |
74 | ||
75 | format = column.getSummaryFormatter() || format; | |
76 | } | |
77 | else if (v === 0 && zeroValue !== null) { | |
78 | v = zeroValue; | |
79 | format = null; | |
80 | } | |
81 | ||
82 | if (format) { | |
83 | v = format(v); | |
84 | } | |
85 | ||
86 | if (v != null) { | |
87 | v = String(v); | |
88 | } | |
89 | else { | |
90 | v = ''; | |
91 | } | |
92 | ||
93 | return v; | |
94 | }, | |
95 | ||
96 | printValue: function(v) { | |
97 | var me = this, | |
98 | was = me.refreshContext, | |
99 | s; | |
100 | ||
101 | // This method is mostly called outside row.refresh(), so we need to spin | |
102 | // up a context... | |
103 | me.refreshContext = me.beginRefresh(was); | |
104 | ||
105 | s = me.formatValue(v); | |
106 | ||
107 | if (me.getEncodeHtml()) { | |
108 | s = Ext.htmlEncode(s); | |
109 | } | |
110 | ||
111 | me.refreshContext = was; | |
112 | ||
113 | return s; | |
114 | }, | |
115 | ||
116 | updateRawValue: function(rawValue) { | |
117 | var dom = this.bodyElement.dom, | |
118 | value = rawValue == null ? '' : rawValue; | |
119 | ||
120 | if (this.getEncodeHtml()) { | |
121 | dom.textContent = value; | |
122 | } | |
123 | else { | |
124 | dom.innerHTML = value; | |
125 | } | |
126 | }, | |
127 | ||
128 | updateValue: function() { | |
129 | var me = this, | |
130 | was = me.refreshContext, | |
131 | row = me.row; | |
132 | ||
133 | // We may be called by binding after the store has already been nullified. | |
134 | // This can happen when binding to an association store if the parent record | |
135 | // is dropped. If that is the case the row will have been removed from the grid | |
136 | // and cached for later use, so we can skip updating the dom. | |
137 | if (row && row.parent) { | |
138 | // We can be called by refresh() or directly such as when binding. | |
139 | // Make sure we have a context spun up... | |
140 | if (!was) { | |
141 | me.refreshContext = me.beginRefresh(); | |
142 | } | |
143 | ||
144 | me.writeValue(); | |
145 | ||
146 | me.refreshContext = was; | |
147 | } | |
148 | }, | |
149 | ||
150 | updateZeroValue: function() { | |
151 | if (!this.isConfiguring) { | |
152 | this.refresh(); | |
153 | } | |
154 | }, | |
155 | ||
156 | writeValue: function() { | |
157 | var me = this, | |
158 | value = me.getValue(); | |
159 | ||
160 | if (!(value = me.formatValue(value))) { | |
161 | // formatValue returns a string, so ! means '' not 0. | |
162 | value = me.getColumn().getEmptyText(); | |
163 | } | |
164 | ||
165 | me.setRawValue(value); | |
166 | } | |
167 | }); |