如何从 angularJS-datatables 中的 dtOptions 访问 table 本身

how to access table itself from dtOptions in angularJS-datatables

我想要一个 csv 下载按钮,需要从 table 中排除几列。

我发现 exportOptions 定义了应该导出哪些列。 此选项来自 jQuery 数据表和 table.column() 方法可能用于 select 列。

现在我需要 select 某些列,但我找不到如何使用 angular-datatable 的方法。

有人知道解决方案吗?

    <table dt-options="dtOptions" dt-column-defs="dtColumnDef">
        <thead>
            <tr>
                <th>hoo</th>
                <th>hoo</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>hoo</td>
                <td>hoo</td>
            </tr>
        </tbody>
    </table>



<script>
    // here is inside my controller

    $scope.dtOptions = DTOptionsBuilder
    .newOptions()
    .withDOM('tB')
    .withButtons([
    {
        text: 'download csv',
        extend: 'csv',
        exportOptions:
        {
            // columns: I neet to select certain columns here
            // wiht method like "table.columns(0)" mentioned in jQuery datatables document
            // but I don't know how in angular-datatables
        }
    }]);
</script>

我使用angular方式渲染table。

angular 方式与纯 jQuery DataTable 没有区别。而且您不需要访问 exportOptions 中的 table 实例。你需要的是return一个column selector;这里有一些例子(不知道你到底想做什么):

exportOptions: {
  columns: [0,4,5] //some columns by index
}
exportOptions: {
  columns: 'th' //any column
}
exportOptions: {
  columns: ['th:eq(1)', 'th:eq(5)'] //same as numbered array
}
exportOptions: {
  columns: 'th:not(:first)' //exclude the first column
} 
exportOptions: {
  columns: 'th:not(.no-export)' //exclude columns with class no-export
} 

等等