Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to get colvis button to function using $.fn.dataTable.defaults #46

Closed
happymacarts opened this issue Jul 14, 2022 · 2 comments · May be fixed by #47
Closed

unable to get colvis button to function using $.fn.dataTable.defaults #46

happymacarts opened this issue Jul 14, 2022 · 2 comments · May be fixed by #47
Assignees
Labels
question Further information is requested

Comments

@happymacarts
Copy link
Contributor

happymacarts commented Jul 14, 2022

In vs 3.0 they seemed to work fine
but after updating I am unable to get this to work right


  $.extend( $.fn.dataTable.defaults, {
        "dom" : '<"datatable"<"btn-toolbar mb-2"B><"d-flex justify-content-between">rt<"d-flex justify-content-between border-top pt-4">>',
        "buttons": [
            'print',            
            {
                  extend: 'csv',
                  text: "Excel",
                  exportOptions: {                      
                      columns: [0, ':visible'],
                  },                  
                  filename: "petitions",
              },
            'copy',
            {
              extend: 'colvis',
              className: 'btn btn-dark',
            }
        ],    	
    })
@wimurk wimurk self-assigned this Jul 19, 2022
@wimurk wimurk added the question Further information is requested label Jul 19, 2022
@wimurk
Copy link
Contributor

wimurk commented Jul 19, 2022

I have tried to add the buttons but on my side it won't work even when adding it directly into the constructor of the $.DataTable config.

What kind of buttons are these?

@happymacarts
Copy link
Contributor Author

$.fn.dataTable.defaults is supposed to allow you to set default parameters for datatable object when options are not declared. but this library is defining most of those properties which is why I found that it will not work this way to leave them undefined. It became easier to just define the properties on my TableModel Object. another noteworthy item is the properties need to be defined in PHP object notation not JSON

public $buttons =  [
        [
            'extend' =>  'print',
            'text' => 'Print',
            'exportOptions' => [
                'columns' => [0, ':visible'],
            ],
        ],
        [
            'extend' => 'csv',
            'text' => 'Excel',
            'exportOptions' => [
                'columns' => [0, '=>visible'],
            ],
            'filename' => 'OnlineRequests',
        ],
        'copy',
        [
            'extend' => 'colvis',
            'className' => 'btn btn-dark'
        ]
    ];

But to explain these are the default DataTable Buttons Extension https://datatables.net/extensions/buttons/ the above would render like this
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants