How to use exportOptions modifier columns to export all exept last column?

How to use exportOptions modifier columns to export all exept last column?

laurynaslaurynas Posts: 1Questions: 1Answers: 0
edited October 2015 in Free community support

So I'm using this new DataTables with dataTables.buttons and I was wondering how do I export all exept the last column.
Could anyone help me out?

$table.dataTable({
buttons:{extend: 'excelHtml5',
                        className: 'my-button-class',
                        title: 'myTitle',
                        text: 'Export',
                        exportOptions: {
                            modifier: {
                                columns: ???
                            }
                        }
                    }
});

This question has an accepted answers - jump to answer

Answers

  • Redbaron67Redbaron67 Posts: 6Questions: 1Answers: 0

    Pretty sure you just list the columns you want exported.

    IE columns:[0,1,2,3]

    If you have 5 columns then you would leave 4 off.

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Since you can use a jQuery selector you can use :not(:last-child) to ignore the last column, or use an array of indexes as Redbaron67 suggests.

    Allan

  • tsprasanthtsprasanth Posts: 5Questions: 2Answers: 1

    can you tell what to do if you want to print specific array of columns which changes on the run.
    exportOptions: {

                                columns:arrayList
    
                }
    
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    @tsprasanth - As in you want to be able to dynamically modify the columns option after initialisation? There is no API for that at the moment. What you could do is use a class name selector and change the class names on the header cells in the table, that would have the same effect.

    Allan

  • rafidheenrafidheen Posts: 2Questions: 0Answers: 0

    Hi Allan,

    can i have any example to achieve dynamically modify the columns option?

    Rafidheen M

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    Sorry if I wasn't clear enough above. There is no option for that at the moment.

    You could use the columns option as a function and dynamically calculate which columns you want to include, but that's about it.

    Allan

  • rafidheenrafidheen Posts: 2Questions: 0Answers: 0

    Allen,

    I tried like this..

    exportOptions: { columns: function () { return [1,2,3]; } }
    the above code does not works. And it exports all the columns in the grid.

    Note : on the above code, instead of [1,2,3]; i will suppose to call my custom function which will return a list of integer array. But the above code itself is not working.

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    That's not how columns works as a function. See the documentation here. Basically it is executed for each column in the table and you need to return true or false to indicate if that column should be included or not (i.e. filter out the ones you don't want).

    Allan

This discussion has been closed.