|
28 | 28 | * <ul style='list-style-type: none'> |
29 | 29 | * <li>.header - (string) Text label for a column header |
30 | 30 | * <li>.itemField - (string) Item field to associate with a particular column. |
31 | | - * <li>.htmlTemplate - (string) (optional) id/name of an embedded ng/html template. Ex: htmlTemplate="name_template.html". The template will be used to render each cell of the column. |
| 31 | + * <li>.templateFn - (function) (optional) Template function used to render each cell of the column. Pro: more performant than `htmlTemplate`. Con: doesn't support AngularJS directives in the template, therefore it doesn't support things like ng-click. Example: <pre>templateFn: value => `<span class="text-danger">${value}</span>`</pre> |
| 32 | + * <li>.htmlTemplate - (string) (optional) id/name of an embedded ng/html template. Pro: supports AngularJS directives in the template. Con: poor performance on large tables. Ex: htmlTemplate="name_template.html". The template will be used to render each cell of the column. |
32 | 33 | * Use <code>handleColAction(key, value)</code> in the template to call the <code>colActionFn</code> callback function you specify. 'key' is the item attribute name; which should equal the itemFld of a column. |
33 | 34 | * 'value' is the item[key] value. |
34 | 35 | * <pre> |
|
39 | 40 | * <li>.colActionFn - (function) (optional) Callback function used for the column. 'value' is passed as a paramenter to the |
40 | 41 | * callback function. |
41 | 42 | * </ul> |
| 43 | + * <p><strong>Tip:</strong> For templating, use `tempateFn` unless you really need to use AngularJS directives. `templateFn` performs better than `htmlTemplate`.</p> |
42 | 44 | * @param {array} actionButtons List of action buttons in each row |
43 | 45 | * <ul style='list-style-type: none'> |
44 | 46 | * <li>.name - (String) The name of the action, displayed on the button |
|
154 | 156 | $scope.actionsText = ""; |
155 | 157 |
|
156 | 158 | $scope.columns = [ |
157 | | - { header: "Status", itemField: "status", htmlTemplate: "status_template.html" }, |
158 | | - { header: "Name", itemField: "name", htmlTemplate: "name_template.html", colActionFn: onNameClick }, |
159 | | - { header: "Age", itemField: "age"}, |
160 | | - { header: "Address", itemField: "address", htmlTemplate: "address_template.html" }, |
161 | | - { header: "BirthMonth", itemField: "birthMonth"} |
| 159 | + { |
| 160 | + header: "Status", |
| 161 | + itemField: "status", |
| 162 | + htmlTemplate: "status_template.html" |
| 163 | + }, |
| 164 | + { |
| 165 | + header: "Name", |
| 166 | + itemField: "name", |
| 167 | + htmlTemplate: "name_template.html", |
| 168 | + colActionFn: onNameClick |
| 169 | + }, |
| 170 | + { |
| 171 | + header: "Age", |
| 172 | + itemField: "age", |
| 173 | + templateFn: function(value) { |
| 174 | + var className = value > 30 ? 'text-success' : 'text-warning'; |
| 175 | + return '<span class="' + className + '">' + value + '</span>'; |
| 176 | + } |
| 177 | + }, |
| 178 | + { |
| 179 | + header: "Address", |
| 180 | + itemField: "address", |
| 181 | + htmlTemplate: "address_template.html" |
| 182 | + }, |
| 183 | + { |
| 184 | + header: "BirthMonth", |
| 185 | + itemField: "birthMonth" |
| 186 | + } |
162 | 187 | ]; |
163 | 188 |
|
164 | 189 | // dtOptions paginationType, displayLength, and dom:"p" are no longer being |
|
0 commit comments