2017-03-07 80 views
0
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,我需要添加導出按鈕。除了顯示導出按鈕外,一切正常。流星中的導出按鈕

回答

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(); 
     } 
     }); 
    } 
    }); 
} 
}); 
0

您是否嘗試將按鈕添加到您的初始化?

+0

這一個沒有工作,需要服裝按鈕 – Mehr