Laravel-datatables: The exportOption 'columns' => ':visible' do not work

Created on 21 Dec 2017  ·  15Comments  ·  Source: yajra/laravel-datatables

Summary of problem or feature request


When exporting, the param :

'exportOptions' => [
                          'columns' => ':visible
                      ],

Do not work

it should enable the option to only export the visible columns and not all.

System details

  • Operating System
    Debian wheezy
  • PHP Version
    PHP 7.1.8
  • Laravel Version
    Laravel Framework 5.5.19
  • Laravel-Datatables Version
yajra/laravel-datatables-buttons      v3.1.0             Laravel DataTables Buttons Plugin.
yajra/laravel-datatables-html         v3.2.1             Laravel DataTables HTML builder plugin for Laravel 5.4+.
yajra/laravel-datatables-oracle       v8.3.2             jQuery DataTables API for Laravel 4|5
question

Most helpful comment

Indeed a workaround is to add a parameter to the function _buildParams
And then cath it in the 'getColumns' method on server side.
I just made a PR for that : https://github.com/yajra/laravel-datatables-buttons/pull/78

All 15 comments

Can you please link me to the datatables.net example of how this is done? This option is a bit new to me. Thanks!

I see, this demo is for printing on client-side implementation. For server-side, unfortunately it's not supported.

@yajra do you think this feature will be implemented in a future version?

It is a bit weird that the printing on the server side takes into account the visibility of the columns, but the xls exporting does not. Is there a reason for the different behavior?

AFAIK, colvis is not also available on server-side implementation on the JS side so it might a bit difficult to implement atm.

For exporting, you can just set exportable to false. Here are some column config the you can use:

  'orderable'      => false,
  'searchable'     => false,
  'exportable'     => false,
  'printable'      => true,
  'visible'        => true,

Any work around this issue or feature yet?

@yajra I think we might pass a variable to _buildParams I'm not sure how to do that yet, but I request you might give me a hint :)

Indeed a workaround is to add a parameter to the function _buildParams
And then cath it in the 'getColumns' method on server side.
I just made a PR for that : https://github.com/yajra/laravel-datatables-buttons/pull/78

Well, now we know how to catch the parameter on the server side, aka backend, but how to send it in the actual dt ajax request? what js we need to edit?

Doesn't work with print! @FabienLucini, only with postcsv visible. not even pdf!

In this POC, I did the changes for postExcel and postCsv
But you can do the same for pdf and print and then adjust your code serverside.
Cheers

@FabienLucini Thank you very much, you really did the trick. You saved me hours of thinking and brain storming.
Sometimes, maybe all the time :D one feels dump, the solution is in front of your eyes, and you can't figure it out. loooool

@yajra Let's implement these changes to the branch.

@FabienLucini @AmirTallap thanks. You can also PR the print part for a hacktobefest points in case you are joining the treat.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mopster picture Mopster  ·  3Comments

nasirkhan picture nasirkhan  ·  3Comments

hohuuhau picture hohuuhau  ·  3Comments

FilipeBorges1993 picture FilipeBorges1993  ·  3Comments

vipin733 picture vipin733  ·  3Comments