Deselect rows in custom print button

Deselect rows in custom print button

bbrindzabbrindza Posts: 300Questions: 69Answers: 1

How would I deselect row in a custom print function?

                { extend: 'print', 
                   //deselect rows before executing any script
                    .....
          }

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    You can call api rows().deselect(),

    Colin

  • bbrindzabbrindza Posts: 300Questions: 69Answers: 1

    I have tried that and received this error in the console log
    Uncaught SyntaxError: Unexpected identifier

    { extend: 'print', 
                         var table = $('#timeLogTable_Home').DataTable(),
                          table.rows('.important').deselect(),
                         
                         init: function(api, node, config) {
                            $(node).removeClass('dt-button buttons-print')
                          },
                         className: 'btn btn-primary',
                         exportOptions: {
                              columns: [ 2, 3, 6, 7, 8, 9, 10, 11, 13, 15]
                         },
        
                        title: 'Week Ending Report '+  $('#weekEndingDate').val() + " for Employee: " + employeeName ,
                
                        customizeData: includeSubtotals,
        
                        customize: function(win) {
                            $(win.document.body).find('h1').css('font-size', '15pt');   
                            $(win.document.body)
                            .css( 'font-size', '8pt' );
        
                           $(win.document.body).find( 'table' )
                           .addClass( 'compact' )
                           .css( 'font-size', 'inherit' );
        
                           var last = null;
                           var current = null;
                           var bod = [];
        
                           var css = '@page { size: landscape; font-size: 8px}',
                           head = win.document.head || win.document.getElementsByTagName('head')[0],
                           style = win.document.createElement('style');
        
                          style.type = 'text/css';
                          style.media = 'print';
        
                          if (style.styleSheet){
                                style.styleSheet.cssText = css;
                         }else{
                               style.appendChild(win.document.createTextNode(css));
                         }
                        head.appendChild(style);
                      }
              }
            ],
            dom: {
                button: { className: 'btn btn-primary'},
                buttonLiner: { tag: null }
               }   
        },    
    
  • kthorngrenkthorngren Posts: 20,257Questions: 26Answers: 4,761

    You will need to create a custom button. Here is an example. The last example in the buttons.buttons.action docs show how to execute the desired export inside the action function.

    Kevin

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    That error is usually accompanied by a line number.
    Otherwise use JSLint to debug your code. It's not a DT error.

This discussion has been closed.