diff --git a/examples/blog/config.js b/examples/blog/config.js index 07c9b038..6ba8d80a 100644 --- a/examples/blog/config.js +++ b/examples/blog/config.js @@ -73,7 +73,7 @@ .description('List of posts with infinite pagination') // description appears under the title .infinitePagination(true) // load pages as the user scrolls .fields([ - nga.field('id').label('ID'), // The default displayed name is the camelCase field name. label() overrides id + nga.field('id').label('id'), // The default displayed name is the camelCase field name. label() overrides id nga.field('title'), // the default list field type is "string", and displays as a string nga.field('published_at', 'date'), // Date field type allows date formatting nga.field('views', 'number'), diff --git a/src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js b/src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js index bb9b468a..ddf2f8e1 100644 --- a/src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js +++ b/src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js @@ -9,15 +9,24 @@ define(function () { scope: { entity: '&' }, - template: '', + template: '', link: function(scope) { scope.entity = scope.entity(); - scope.view = scope.entity.exportView(); - var formatEntry = entryFormater.getFormatter(scope.view.fields()); + var exportView = scope.entity.exportView(); + var listView = scope.entity.listView(); + if (exportView.fields().length === 0) { + var exportFields = listView.exportFields(); + if (exportFields === null) { + exportFields = listView.fields(); + } + exportView.fields(exportFields); + } + scope.has_export = exportView.fields().length > 0; + var formatEntry = entryFormater.getFormatter(exportView.fields()); scope.exportToCsv = function () { - RetrieveQueries.getAll(scope.view, -1, true, $stateParams.search, $stateParams.sortField, $stateParams.sortDir).then(function (response) { + RetrieveQueries.getAll(exportView, -1, true, $stateParams.search, $stateParams.sortField, $stateParams.sortDir).then(function (response) { var results = [], entries = response.entries; for (var i = entries.length - 1; i >= 0; i--) { results[i] = formatEntry(entries[i]); diff --git a/src/javascripts/ng-admin/es6/lib/View/ExportView.js b/src/javascripts/ng-admin/es6/lib/View/ExportView.js index fe56fc43..3a81f20e 100644 --- a/src/javascripts/ng-admin/es6/lib/View/ExportView.js +++ b/src/javascripts/ng-admin/es6/lib/View/ExportView.js @@ -3,6 +3,7 @@ import ListView from './ListView'; class ExportView extends ListView { constructor(name) { super(name); + this._fields = []; this._type = 'ExportView'; } } diff --git a/src/javascripts/ng-admin/es6/lib/View/ListView.js b/src/javascripts/ng-admin/es6/lib/View/ListView.js index 8e9ae977..2cb49728 100644 --- a/src/javascripts/ng-admin/es6/lib/View/ListView.js +++ b/src/javascripts/ng-admin/es6/lib/View/ListView.js @@ -10,6 +10,7 @@ class ListView extends View { this._listActions = []; this._batchActions = ['delete']; this._filters = []; + this._exportFields = null; this._sortField = 'id'; this._sortDir = 'DESC'; @@ -64,6 +65,16 @@ class ListView extends View { return this; } + exportFields(exportFields) { + if (!arguments.length) { + return this._exportFields; + } + + this._exportFields = exportFields; + + return this; + } + batchActions(actions) { if (!arguments.length) { return this._batchActions;