Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Fix invalid reference to entry in datagrid header #708

Merged
merged 2 commits into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions doc/Configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,15 @@ Set field validation rules. Based on Angular's form validation features.
} })

* `cssClasses(String|Function)`
A list of CSS classes to be added to the corresponding field. If you provide a function, it will receive the current entry as first argument, to allow dynamic classes according to values.
A list of CSS classes to be added to the corresponding field. If you provide a function, it will receive the current entry as first argument, to allow dynamic classes according to values. The function will also be called without entry for table headers.

nga.field('title')
.cssClasses(function(entry) {
return entry.values.needsAttention ? 'bg-warning' : '';
if(entry) {
return entry.values.needsAttention ? 'bg-warning' : '';
}

return 'my-custom-css-class-for-list-header';
});

* `defaultValue(*)`
Expand Down Expand Up @@ -511,11 +515,11 @@ Format for number to string conversion. Based on [Numeral.js](http://numeraljs.c
A field of type `boolean` can have 3 values: true, false, or null. That's why the form widget for such a field is a dropdown and not a checkbox.

* `choices(array)`
Array of choices used for the boolean values. By default:
Array of choices used for the boolean values. By default:

[
{ value: null, label: 'undefined' },
{ value: true, label: 'true' },
{ value: true, label: 'true' },
{ value: false, label: 'false' }
]

Expand Down
8 changes: 5 additions & 3 deletions examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@
nga.field('id').label('ID'),
nga.field('name'),
nga.field('published', 'boolean').cssClasses(function(entry) { // add custom CSS classes to inputs and columns
if (entry.values.published) {
return 'bg-success text-center';
if(entry){
if (entry.values.published) {
return 'bg-success text-center';
}
return 'bg-warning text-center';
}
return 'bg-warning text-center';
}),
nga.field('custom', 'template')
.label('Upper name')
Expand Down
3 changes: 1 addition & 2 deletions src/javascripts/ng-admin/Crud/list/maDatagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ define(function (require) {
<th ng-if="selection">
<ma-datagrid-multi-selector toggle-select-all="toggleSelectAll()" selection="selection" entries="entries"/>
</th>
<th ng-repeat="field in fields() track by $index" ng-class="field.getCssClasses(entry)"
class="ng-admin-column-{{ ::field.name() }} ng-admin-type-{{ ::field.type() }}">
<th ng-repeat="field in fields() track by $index" ng-class="field.getCssClasses()" class="ng-admin-column-{{ ::field.name() }} ng-admin-type-{{ ::field.type() }}">
<a ng-click="datagrid.sort(field)">
<span class="glyphicon {{ datagrid.sortDir === 'DESC' ? 'glyphicon-chevron-down': 'glyphicon-chevron-up' }}" ng-if="datagrid.isSorting(field)"></span>

Expand Down