angularjs - 仅将过滤后的数据导出到 Angular 智能表中的 csv 中

标签 angularjs smart-table

我们已经使用 Angular 智能表实现了一个报告表。当用户使用 st-search 应用搜索条件时,我们需要将所有项目导出到 csv。我们使用了 ng-csv 指令进行导出。使用st-table数组集合时,只获取第一页数据。也就是说过滤后共有7条记录,第一页显示5项,仅导出此数据(5项)。如何导出所有过滤数据?

 <table class="table table-striped" st-table="displayed">
<thead>
<tr>
    <th  st-sort="firstName">first name</th>
    <th  st-sort="lastName">last name</th>
    <th  st-sort="birthDate">birth date</th>
    <th  st-sort="balance">balance</th>
    <th >email</th>
</tr>
<tr>
    <th>
        <input st-search="firstName" placeholder="search for firstname" class="input-sm form-control" type="search"/>
    </th>
    <th colspan="4">
        <input st-search placeholder="global search" class="input-sm form-control" type="search"/>
    </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in displayed">
    <td>{{row.firstName | uppercase}}</td>
    <td>{{row.lastName}}</td>
    <td>{{row.birthDate | date}}</td>
    <td>{{row.balance | currency}}</td>
    <td><a ng-href="mailto:{{row.email}}">email</a></td>
</tr>
</tbody>
<tfoot>
        <tr>
            <td colspan="5" class="text-center">
                <div st-pagination="" st-items-by-page="5" st-displayed-pages="10"></div>
            </td>
        </tr>
    </tfoot>

最佳答案

您可以通过表 Controller api 访问过滤后的集合。所以你只需要创建一个需要 stTable Controller 的指令:

.directive('stExport',function(){
   return {
     require:'^stTable',
     link:function(scope, element, attr,ctrl){
       element.bind('click',function(){
       alert(ctrl.getFilteredCollection().length);
     })
   };
}

have a look at that running example

关于angularjs - 仅将过滤后的数据导出到 Angular 智能表中的 csv 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31987451/

相关文章:

html - 使用来自 REST 服务的数据时,分页不适用于智能表

angularjs - Shibboleth SSO CORS 错误

events - 从 angularjs 指令触发点击事件

angularjs - 动态更改Recaptcha V2语言

javascript - Angularjs 单选按钮未选择名称

AngularJS Smarttable - 选择事件

javascript - 带有 Angular 1.5.8 的智能表 - 行选择不起作用 - 范围未填写

javascript - AngularJS——创建自定义数据绑定(bind)和 ng-repeat

javascript - 如何使按钮在 AngularJS 的智能表格的第一页和最后一页上跳过

javascript - 智能表 : set page programmatically