2016-03-23 4 views
1

私は今朝から大きな問題に直面しています。私はテーブルをpdfファイルにエクスポートしようとしています。私が何もせずにそれを置くと、スクリプトはうまく動作し、ページの読み込みとdlが始まります。未知のタイプエラーを取得する:私がボタンで私の.tableExportを使用しようとすると

しかし、私はボタンでそれをしたい!私はこのようにそれを置くときと:

$(document).ready(function() { 
    $('#downloadPDF').on('click', function (e) { 
     console.log("test"); 
     e.preventDefault(); 
     $('table').tableExport({ 
      type: 'pdf', 
      jspdf: {  
       orientation: 'l', 
       format: 'a3', 
       margins: { 
        left: 10, 
        right: 10, 
        top: 20, 
        bottom: 20 
       }, 
       autotable: { 
        styles: { 
         fillColor: 'inherit', 
         textColor: 'inherit' 
        }, 
        tableWidth: 'auto' 
       } 
      } 
     }); 
    }); 
}); 
<button type="button" id="downloadPDF" class="btn btn-default">Default</button> 

私はクロームコンソールでこのエラーを取得:

Uncaught TypeError: $(...).tableExport is not a function(anonymous function) @ Auto:290jQuery.event.dispatch @ jquery-1.10.2.js:5109elemData.handle @ jquery-1.10.2.js:4780

私は理由を理解することはできません。イベントに参加していないときはうまく動作するからです。

+1

'$( 'table')'とは何ですか? –

+0

これは私のテーブルのIDです –

+0

それは '$( '#table')' –

答えて

0

これを行うには、a table export pluginが必要です。

は、あなたのページでこれらの輸入品を追加します。明らかに

<script type="text/javascript" src="tableExport.js"> 
<script type="text/javascript" src="jquery.base64.js"> 

//and these if you want export to pdf 
<script type="text/javascript" src="jspdf/libs/sprintf.js"> 
<script type="text/javascript" src="jspdf/jspdf.js"> 
<script type="text/javascript" src="jspdf/libs/base64.js"> 

、あなたがそれをダウンロードしたことにより、SRCパスを交換してください。

+0

既にこのページがあります –

関連する問題