Search code examples
pdfdatatables

DataTable PDF Export orders wrong


My dataTable automatically is ordered by the third column with the setting order: [2, 'asc'] in the config. This works correctly. In the buttons section on the config I added the setting exportOptions: { modifier: {search: 'none', order: 'original'} } with the expectation that this would order the exported table by the third column as well. However when I do export the table, it is ordered by the second column instead.

Is there any way to fix this?


Solution

  • I use this config with the csv button. I assume it will be the same for pdf

    {
        extend: 'csv',
        className: 'btn btn-info btn-sm',
        exportOptions: {
            filter: 'applied',
            order: 'current'
        }
    }
    

    According to https://datatables.net/forums/discussion/45560/set-order-for-export-to-excel-pdf you can set the order value to index if you want the original order

    modifier: { order: 'index' }