0

Could someone let me know why am i getting this error.

Uncaught TypeError: this.movie.setSheetName is not a function

While using the buttons in Angularjs Datatable mentioned here

https://l-lin.github.io/angular-datatables/#/withButtons

Here is the code

$rootScope.dtOptions = DTOptionsBuilder.newOptions()
    .withPaginationType('full_numbers')
    .withDisplayLength(10)
    .withDOM('frtip')
    .withBootstrap()
    .withBootstrapOptions({
        TableTools: {
            classes: {
            container: 'btn-group',
                buttons: {
                    normal: 'btn btn-danger'
                }
            }
        },
        ColVis: {
            classes: {
                masterButton: 'btn btn-primary'
            }
        },
        pagination: {
            classes: {
                ul: 'pagination pagination-sm'
            }
        }
    })
    .withOption('bLengthChange', false).withButtons([
        'copy',
        'print',
        'excel'
    ]);
Aftershock
  • 5,205
  • 4
  • 51
  • 64
af_khan
  • 1,030
  • 4
  • 25
  • 49

1 Answers1

1

You need to have jszip installed. Include this line to your bower.json dependencies section (if you are using bower)

"dependencies": {
   ...
   "jszip": "2.6.0" 
}

and run a bower update. Or use npm :

npm install jszip@2.6.0

It is important that you are specific about using 2.6.0 (or lower). dataTables is not compatible with the latest 3.0.0.


Update; setting the filename :

.withButtons([ 
    { 
      extend : 'excel'
      filename: 'download', 
    },
    ...
])

This will result in a file named download.xlsx

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
  • after adding this, it is saving the data as blob object .xlsx but not with any file name – af_khan May 11 '16 at 10:28
  • @Yahiya, just specify a filename as well - see update. – davidkonrad May 11 '16 at 10:42
  • Superb !! one last question though. I see the file is saved with say 210 Kb but when i open the file its empty. I am on linux mint with open office – af_khan May 11 '16 at 10:49
  • @Yahiya, I dont know. Using linux and LibreOffice myself, have no problems with Excel, CSV, PDF or similar. Try using `extend: 'excelHtml5'` instead of `extend: 'excel'`. `'excel'` is actually a "fallback" to use the flash-version if available. Otherwise, the only known problem with excel is with Safari due to an webkit error (see [*'docs**](https://datatables.net/reference/button/excelHtml5)) – davidkonrad May 11 '16 at 10:59
  • dint work. may be some issue with openoffice, but anyway, your answers helped me and now am able to save the files. Thank you @davidkonrad. – af_khan May 11 '16 at 11:05