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 bug on export with field of type template #949

Merged
merged 2 commits into from
Mar 2, 2016
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
19 changes: 19 additions & 0 deletions doc/reference/View.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ Set the fields for the CSV export function. By default, ng-admin uses the fields
.stripTags(true)
]);

Be careful if you don't define explicitly your `exportFields` (and so the fields displayed in the datagrid will be used) you may have strange results with fields of type `template`!
For example, if you define:

nga.field('picture', 'template')
.template('<img src="{{ entry.values.picture }}" />')

The exported value will be :

<img src="{{ entry.values.picture }}" />

To fix that, you have to set your `.template` with a function :

nga.field('picture', 'template')
.template((entry) => `<img src="${entry.values.picture}" />`)

In this case, the exported value will be :

<img src="http://mydomain.com/myPicture.png" />

* `exportOptions(Object)`
Customize the CSV export format (quotes, delimiter, newline). The default options object is `{ quotes: false, delimiter: ",", newline: "\r\n" }`.

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/misc/EntryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class EntryFormatter {
return function (entry) {
return {
name: label,
value: field._template(entry)
value: field.getTemplateValue(entry)
};
};
case 'number':
Expand Down