2
我想将角度数据表中的数据导出到Excel表格中。我成功地将整个Json对象导出到Excel工作表中。导出过滤/搜索从角度数据表导入数据到Excel
我在找的是获取搜索/过滤的数据只导出到Excel中,如果搜索为空,则导出所有数据。
对于参考让我告诉你我的代码是如何
这是我的控制器
userService.getUserList(function(response) {
if (response.status === 200) {
vm.users = response.data.userDetails;
return;
}
if (response.status === 400) {
return toastr.error(response.data.exception);
}
});
vm.exportData = function() {
vm.listOfUsers = angular.copy(vm.users);
vm.filteredData = _.map(vm.listOfUsers, function(data){
var status = (data.isActive==true)?'Active':'In-Active';
var users = {'Name': data.fullName, 'Email': data.email, 'Designation': data.designation, 'Company Name': data.companyName,'Status':status}
return users;
});
alasql('SELECT * INTO XLSX("download.xlsx",{headers:true}) FROM ?', [vm.filteredData]);
}
这是我的HTML
<div class="table-toolbar">
<div class="row">
<div class="col-md-6">
<div class="btn-group">
<button id="sample_editable_1_new" class="btn sbold green" ng-click="vm.exportData()">Export As Excel</button>
</div>
</div>
</div>
</div>
<div class="dataTables_wrapper no-footer">
<table class="table table-striped table-bordered table-hover dataTable" datatable="ng" id="sample_1">
<thead>
<tr>
<th> Sl. No. </th>
<th> Name </th>
<th> Email </th>
<th> Designation </th>
<th> Company Name </th>
<th> Status </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in vm.users">
<td> {{$index+1}} </td>
<td> {{user.fullName}} </td>
<td> {{user.email}} </td>
<td> {{user.designation}} </td>
<td> {{user.companyName}} </td>
<td>{{user.isActive === true? "Active" : "In-Active" }}
</td>
</tr>
</tbody>
</table>
由于数据表具有内置功能搜索,当用户键入一些东西时,它开始搜索,所以当用户搜索,然后单击导出按钮,然后我只想传递与搜索查询相关的数据,以便只将这些数据导出到Excel中。