简体   繁体   English

用于动态表的jspdf自动表

[英]jspdf autotable for dynamic table

I have used auto table for for dynamically generated table.It will display 1 or 2 or 3 table based on rsponse.我已将自动表用于动态生成的表。它将根据 rsponse 显示 1 或 2 或 3 个表。 but not more than 3 tables.I want to display the align two table in single row.If third one occur with will display below the table.但不超过 3 个表格。我想在单行中显示对齐两个表格。如果出现第三个表格,将显示在表格下方。 I have tried as我试过了显示 3 行文字 . .

for me If 1st and 3rd table comes It will shows 1st in left side first row and 3rd displays below the 1st table which I want to display right side in 1st row.对我来说,如果第一个和第三个表出现,它将在左侧第一行显示第一个,第三个显示在我想在第一行显示右侧的第一个表下方。

显示第 1 行和第 3 行

 function generate(enhance) { group1='1'; group2=''; group3='1'; //const doc = new jsPDF('l', 'mm'); const doc = new jsPDF('p', 'pt', 'a4'); var i=0; if(group1.length){ i+=1; if ( i % 2 == 0) { alert('Even Number'); displayposition='left'; }else{ alert('odd Number'); displayposition='right'; } var res = doc.autoTableHtmlToJson(document.getElementById('geo_summarynew')); doc.text(7, 15, "Pipeline as of july"); doc.autoTable(res.columns, res.data,{ startY: 30, showHead: 'firstPage', styles: { overflow: 'hidden',fontSize:5}, margin: { right: 305 }, });} if(group2.length){ i+=1; if ( i % 2 == 0) { alert('Even Number'); displayposition='left'; }else{ alert('odd Number'); displayposition='right'; } var res3 = doc.autoTableHtmlToJson(document.getElementById('group2new')); doc.text(7, 15, "close won "); doc.autoTable(res3.columns, res3.data,{ startY: 30, showHead: 'firstPage', styles: { overflow: 'hidden',fontSize:5 }, margin: { left: 305 }, });} if(group3.length){ i+=1; if ( i % 2 == 0) { alert('Even Number'); displayposition='left'; }else{ alert('odd Number'); displayposition='right'; } var res4 = doc.autoTableHtmlToJson(document.getElementById('group3new')); doc.autoTable(res4.columns, res4.data,{ startY: doc.lastAutoTable.finalY + 50, showHead: 'firstPage', styles: { overflow: 'hidden',fontSize:5}, margin: { right: 305 }, });} doc.save('test Report'); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://unpkg.com/jspdf"></script> <script src="https://simonbengtsson.github.io/jsPDF-AutoTable/dist/jspdf.plugin.autotable.js"></script> <button id="cmd" class="pdf-download" onclick="generate(true)">Make PDF</button> <table id="geo_summarynew"> <thead><tr class="hidden1"><th data-style="Header" style="background-color: #66cdf2; color: #000">Opportunity</th><th data-style="Header" style="background-color: #66cdf2; color: #000">Pipeline Count</th><th data-style="Header" style="background-color: #66cdf2; color: #000">Pipeline Value</th></tr> </thead> <tbody><tr><td>Qualified</td><td>29</td><td>8156520</td></tr><tr><td>Proposal Submitted</td><td>50</td><td>22949308</td></tr></tbody> </table> <table id="group2new"> <thead><tr class="hidden1"><th data-style="Header" style="background-color: #66cdf2; color: #000">Opportunity</th><th data-style="Header" style="background-color: #66cdf2; color: #000">Pipeline Count</th><th data-style="Header" style="background-color: #66cdf2; color: #000">Pipeline Value</th></tr><tr></tr> </thead> <tbody><tr><td>Closed Won</td><td>65</td><td>15712559</td></tr></tbody> </table> <table id="group3new"> <thead><tr class="hidden1"><th data-style="Header" style="background-color: #66cdf2; color: #000">Opportunity</th><th data-style="Header" style="background-color: #66cdf2; color: #000">Pipeline Count</th></tr><tr></tr> </thead> <tbody><tr><td>Closed Lost</td><td>156</td></tr></tbody> </table>

You did everything so well.你做的一切都那么好。 Just modified your code a bit.只是稍微修改了您的代码。

I tested with 2 cases: 3 tables and 2 tables.我测试了 2 个案例:3 个表和 2 个表。

Here is the sample.这是示例。 I hope the result as you expected, my friend:))我希望结果如你所愿,我的朋友:))

function generate(enhance) {
    group1='1';
    group2=''; 
    group3='1';
    
  //const doc = new jsPDF('l', 'mm');
 const doc = new jsPDF('p', 'pt', 'a4');
 var i=0;
 if(group1.length){
     i+=1;
     if ( i % 2 == 0) {    
    displayposition='left';
}else{    
    displayposition='right';
}

  var res = doc.autoTableHtmlToJson(document.getElementById('geo_summarynew'));
  doc.text(7, 15, "Pipeline as of july");
 doc.autoTable(res.columns, res.data,{
   
         startY: 30,
    showHead: 'firstPage',
    styles: { overflow: 'hidden' ,fontSize:5},
    margin: { right: 305 },
  });}
 if(group2.length){
     i+=1;
     if ( i % 2 == 0) {    
    displayposition='left';
}else{    
    displayposition='right';
}
  var res3 = doc.autoTableHtmlToJson(document.getElementById('group2new'));
  doc.text(300, 15, "close won ");
 doc.autoTable(res3.columns, res3.data,{
   
         startY: 30,
    showHead: 'firstPage',
    styles: { overflow: 'hidden',fontSize:5 },
    margin: { left: 305 },
  });}
 if(group3.length){
     i+=1;
     if ( i % 2 == 0) {    
    displayposition='left';
}else{    
    displayposition='right';
}
  var res4 = doc.autoTableHtmlToJson(document.getElementById('group3new'));
  
  let start_y = 30;
  let margin_left = 0;
  let margin_right = 0;
  if(group2.length){
    start_y = doc.lastAutoTable.finalY + 50;
    margin_right = 305;
    margin_left = 40;
    }
    else{   
    margin_left = 305;
    margin_right = 40;
    }
  
 doc.autoTable(res4.columns, res4.data,{
   
         startY: start_y,
    showHead: 'firstPage',
    styles: { overflow: 'hidden' ,fontSize:5},
    margin: { left: margin_left, right: margin_right },
  });
}
   doc.save('test Report');
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM