Restriction on no of column export

Restriction on no of column export

@nuj_3313@nuj_3313 Posts: 15Questions: 5Answers: 0
edited July 2020 in Free community support

Hi all,
Is there a way to restrict the user to export the n no of columns.
Basically i want to do this for pdf exports to protect the page layout. I know there is other way to set the page sizes but it will be good if i can restrict to n no of columns and show a message. I can have 100's of columns in the table so.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    See if this thread asking a similar question helps.

    Kevin

  • @nuj_3313@nuj_3313 Posts: 15Questions: 5Answers: 0
    edited July 2020

    No... that is different requirement.
    My requirement is to force user to hide some column using colvis button while exporting to pdf if trying to export more than n no of columns.
    Please help

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited July 2020 Answer ✓

    Here are some ideas:

    You can use the column-visibility event to determine if the number of visible columns, using columns().visible(), is good for export. You could use button().enable() and button().disable() based on the number of visible columns.

    You can use buttons.buttons.action to determine the number of visible columns, using columns().visible(), and execute the export if the number is good. See the third example in the buttons.buttons.action docs.

    There are probably other ways you can combine these to meet your requirements.

    Kevin

  • @nuj_3313@nuj_3313 Posts: 15Questions: 5Answers: 0
    edited July 2020

    Got it Thanks @kthorngren
    I have used buttons.buttons.action and jquery to get the no of column like below

       buttons: [{
       extend: 'pdf',
       text: 'Create pdf',
       action: function ( e, dt, node, config ) {
       var columnCount = 0;
       $("table#tableId thead tr.className th").each(function(){
        columnCount++;
    });
    if(columnCount > 15){   
           alert('message');
           return false;
        }
       $.fn.dataTable.ext.buttons.pdfHtml5.action.call(this, e, dt, node, config);
     }}, 'colvis']
    
This discussion has been closed.