Skip to content

Commit fa133e6

Browse files
Alexander ZhukAlexander Zhuk
Alexander Zhuk
authored and
Alexander Zhuk
committed
Export grid data #54 fix - feature added
1 parent 70e8cc7 commit fa133e6

File tree

6 files changed

+956
-1167
lines changed

6 files changed

+956
-1167
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Demo Angular UI Router: http://angular-data-grid.github.io/demo/bootstrap/ui-rou
1717
- Built-in sync with browser address bar (URL), so you can copy-n-paste sorting/filtering/pagination results URL and open it in other browser / send to anyone - even if pagination / filtering are done on a client-side. [See details](#url-synchronization)
1818
- Support of [Angular UI Router](https://github.com/angular-ui/ui-router) navigation.
1919
- Optional support of fixed header table: [Bootstrap Demo](http://angular-data-grid.github.io/demo/fixed-header/bootstrap-grid.html) [Material Design Demo](http://angular-data-grid.github.io/demo/fixed-header/angular-md-grid.html)
20+
- Optional support of CSV data exports: [Demo](http://angular-data-grid.github.io/demo/bootstrap/)
2021
- Unlike most part of other Angular DataGrids, we intentionally use non-isolated scope of the directive to maximize flexibility, so it can be easily synchronized with any data changes inside your controller.
2122
NOTE! With great power comes great responsibility, so use non-isolated API wisely.
2223

Diff for: demo/bootstrap/index.html

+23-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
<div class="container">
3131
<div class="margin-bottom-basic">
3232
<h3>Angular Data Grid sample using out-of-box Bootstrap styling</h3>
33-
Features enabled: sorting, filtering (using both in-grid and external controls), sync with browser URLs, pagination and items-per-page functionality.
33+
Features enabled: sorting, filtering (using both in-grid and external controls), sync with browser URLs,
34+
pagination and items-per-page functionality, plus optional plugin for CSV exports.
3435
Angular UI Datepicker used for date controls, although you can use any other framework, plugin or styling.
3536
<a href="https://github.com/angular-data-grid/angular-data-grid.github.io" target="_blank">Project GitHub</a>
3637
</div>
@@ -88,7 +89,7 @@ <h4>Additional Demos</h4>
8889
ng-focus="gridActions.filter()"
8990
show-weeks="false"
9091
close-text="Close"/>
91-
<span class="input-group-btn">
92+
<span class="input-group-btn">
9293
<label for="dateFromFilter" class="btn btn-default">
9394
<i class="fa fa-calendar"></i></label>
9495
</span>
@@ -118,7 +119,7 @@ <h4>Additional Demos</h4>
118119
ng-focus="gridActions.filter()"
119120
show-weeks="false"
120121
close-text="Close">
121-
<span class="input-group-btn">
122+
<span class="input-group-btn">
122123
<label for="dateToInput" class="btn btn-default">
123124
<i class="fa fa-calendar"></i></label>
124125
</span>
@@ -131,6 +132,13 @@ <h4>Additional Demos</h4>
131132
</div>
132133
</div>
133134
<hr>
135+
<div class="text-right">
136+
<button class="btn btn-default" ng-click="exportToCsv(gridOptions.data)">Export all data to CSV <i
137+
class="fa fa-download"></i></button>
138+
<button class="btn btn-default" ng-click="exportToCsv(gridOptions.grid.filtered)">Export filtered data to CSV <i
139+
class="fa fa-download"></i></button>
140+
</div>
141+
<hr>
134142
<div class="row">
135143
<div class="col-md-12">
136144
<div grid-data id='test' grid-options="gridOptions" grid-actions="gridActions">
@@ -151,7 +159,9 @@ <h4>Additional Demos</h4>
151159
</div>
152160
<div class="form-group items-per-page">
153161
<label for="itemsOnPageSelect1">Items per page:</label>
154-
<select id="itemsOnPageSelect1" class="form-control input-sm" ng-init="paginationOptions.itemsPerPage = '10'" ng-model="paginationOptions.itemsPerPage" ng-change="reloadGrid()">
162+
<select id="itemsOnPageSelect1" class="form-control input-sm"
163+
ng-init="paginationOptions.itemsPerPage = '10'"
164+
ng-model="paginationOptions.itemsPerPage" ng-change="reloadGrid()">
155165
<option>10</option>
156166
<option>25</option>
157167
<option>50</option>
@@ -208,7 +218,8 @@ <h4>Additional Demos</h4>
208218
</div>
209219
<div class="form-group items-per-page">
210220
<label for="itemsOnPageSelect2">Items per page:</label>
211-
<select id="itemsOnPageSelect2" class="form-control input-sm" ng-init="paginationOptions.itemsPerPage = '10'"
221+
<select id="itemsOnPageSelect2" class="form-control input-sm"
222+
ng-init="paginationOptions.itemsPerPage = '10'"
212223
ng-model="paginationOptions.itemsPerPage" ng-change="reloadGrid()">
213224
<option>10</option>
214225
<option>25</option>
@@ -224,14 +235,16 @@ <h4>Additional Demos</h4>
224235
<div>
225236
<button class="btn btn-info margin-bottom-basic" ng-click="showCode = !showCode">CodePen</button>
226237
<div ng-show="showCode">
227-
<p data-height="768" data-theme-id="21603" data-slug-hash="xZddZm" data-default-tab="html" data-user="AngularDataGrid" class='codepen'>See the Pen <a
228-
href='http://codepen.io/AngularDataGrid/pen/xZddZm/'>xZddZm</a> by AngularDataGrid (<a href='http://codepen.io/AngularDataGrid'>@AngularDataGrid</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
238+
<p data-height="768" data-theme-id="21603" data-slug-hash="xZddZm" data-default-tab="html"
239+
data-user="AngularDataGrid" class='codepen'>See the Pen <a
240+
href='http://codepen.io/AngularDataGrid/pen/xZddZm/'>xZddZm</a> by AngularDataGrid (<a
241+
href='http://codepen.io/AngularDataGrid'>@AngularDataGrid</a>) on <a href='http://codepen.io'>CodePen</a>.
242+
</p>
229243
<script async src="//assets.codepen.io/assets/embed/ei.js"></script>
230244
</div>
231245
</div>
232246
<hr>
233247
</div>
234-
</body>
235248
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
236249
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
237250
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
@@ -240,6 +253,7 @@ <h4>Additional Demos</h4>
240253
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-messages.min.js"></script>
241254
<script src="../../dist/pagination.min.js"></script>
242255
<script src="../../dist/dataGrid.min.js"></script>
256+
<script src="../../dist/JSONToCSVConvertor.min.js"></script>
243257
<script src="js/demoApp.js"></script>
244-
258+
</body>
245259
</html>

Diff for: demo/bootstrap/js/demoApp.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
angular.module('myApp', ['ui.bootstrap', 'dataGrid', 'pagination'])
2-
.controller('myAppController', ['$scope', 'myAppFactory', function ($scope, myAppFactory) {
2+
.controller('myAppController', ['$scope', 'myAppFactory', '$filter', function ($scope, myAppFactory, $filter) {
33

44
$scope.gridOptions = {
55
data: [],
@@ -10,6 +10,19 @@ angular.module('myApp', ['ui.bootstrap', 'dataGrid', 'pagination'])
1010
$scope.gridOptions.data = responseData.data;
1111
});
1212

13+
$scope.exportToCsv = function (currentData) {
14+
var exportData = [];
15+
currentData.forEach(function (item) {
16+
exportData.push({
17+
'Code': item.code,
18+
'Date Placed': $filter('date')(item.placed, 'shortDate'),
19+
'Status': item.statusDisplay,
20+
'Total': item.total.formattedValue
21+
});
22+
});
23+
JSONToCSVConvertor(exportData, 'Export', true);
24+
}
25+
1326
}])
1427
.factory('myAppFactory', function ($http) {
1528
return {

0 commit comments

Comments
 (0)