javascript
====
angular.module('app', ['ui.bootstrap', 'ui.grid', 'ui.grid.exporter']);
$scope.gridOptions = {
exporterCsvFilename: 'filename.csv', // 指定csv檔名
exporterOlderExcelCompatibility: true, // 用excel開啟時避免中文亂碼
exporterFieldCallback: function (grid, row, col, value) {
if (col.name === '下次入住') {
value = $filter('date')(value, "yyyy/MM/dd HH:mm"); // 日期欄位改為常見格式
}
return value;
},
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
}
}
$scope.export = function () {
$scope.gridApi.exporter.csvExport("all", "all"); // 匯出csv
};
html
====
<div ui-grid-exporter="" ui-grid="gridOptions"></div>
<button class="btn btn-default" ng-click="export()">匯出</button>
沒有留言:
張貼留言