排除最后一列的jQuery DataTables.net TableTools

问题描述:

问题:使用TableTools附加组件导出时,如何排除jQuery DataTables.net的最后一列?

Question: How can I exclude the last column of jQuery DataTables.net when using the TableTools extras to export?

详细信息

我正在使用jQuery DataTables.net和TableTools附件初始化几个不同的表。他们都使用相同的初始化代码。

I'm initializing several different tables with jQuery DataTables.net and the TableTools extras. They all use the same initialization code.

不同的表具有不同的列数。但是,所有表都有最后一列,这是一个带有按钮的动作列。当使用TableTools导出时,它包括导出中此列中的某些元素。我想排除所有表的TableTools导出的操作列。

The different tables have different number of columns. However, all tables have the last column in common, which is an 'action' column with buttons. When exporting with TableTools, it includes certain elements from this column in the export. I would like to exclude the action column for the TableTools exports for all tables.

我知道 mColumns 选项,但您需要知道列数,这在我所描述的场景中不起作用,所以请不要给我答案如下:

I am aware of the mColumns option but it appears you need to know the number of columns, which doesn't work in my described scenario, so please don't give me answers such as this one:

"mColumns": [ 0, 1, 4 ]

谢谢

tabletools 2.2.3 中的$ b现在可以使用mColumns的功能

Just for googlers: in tabletools 2.2.3 you can now use function for mColumns

var dataTable = $grdData.DataTable({
     tableTools: {
          aButtons: [{
              "sExtends": "csv",
              "sButtonText": "csv",
              "mColumns": function ( dtSettings ) {
                   var api = new $.fn.dataTable.Api( dtSettings );

                   return api.columns(":not(:last)").indexes().toArray();
              }
          }]
     }
});