在流星中导出按钮

时间:2017-03-07 04:40:10

标签: html meteor datatables

Template.users.rendered = function () {
    Template.instance().subscribe('userList');
    if (Session.get('apply_tablestyling')==1) {
        console.log('in datatable');
        $('#users').dataTable({
            "paging": true,
            "lengthChange": false,
            "searching": true,
            "ordering": true,
            "info": true,
            "autoWidth": false
        });
    }
}

我正在使用datatables-bootstrap-3,我需要添加导出按钮。除了显示导出按钮外,一切正常。

2 个答案:

答案 0 :(得分:0)

您是否尝试过添加按钮进行初始化?

buttons: ['copy', 'csv', 'excel', 'pdf', 'print']

答案 1 :(得分:0)

dom: 'Bfrtip',
                  buttons: [
                              {
                          text: 'Export to JSON',
                          action: function ( e, dt, node, config ) {

                            var data = dt.buttons.exportData();
                              $.fn.dataTable.fileSave(
                                  new Blob( [ beautify(data , null, 2, 100) ] ),
                                  'Families_'+ Date.now() +'.json'
                              );
                          }
                      }
                      ,{
                          text: 'Export to CSV',
                          action: function ( e, dt, node, config ) {

                            var data = dt.buttons.exportData();
                              $.fn.dataTable.fileSave(
                                  new Blob( [json2csv({ data: data.body, fields: null })]),
                                  'Families_'+ Date.now() +'.csv'
                              );
                          }
                      }
                  ]

然后在两个routes.js中:

Router.route('/users', {
name: 'users',
action: function() {
    var self = this;
    $.getScript('https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js', function(data, textStatus, jqxhr) {
    if(jqxhr.status === 200) {
      //self.render();
      $.getScript('https://cdn.datatables.net/buttons/1.2.4/js/buttons.html5.min.js', function(data, textStatus, jqxhr) {
      if(jqxhr.status === 200) {
        self.render();
      }
      });
    }
   });
}
});