在jsPdf AutoTable中尝试动态数据时遇到麻烦 [英] Getting trouble while trying Dynamic Data in jsPdf AutoTable

查看:82
本文介绍了在jsPdf AutoTable中尝试动态数据时遇到麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jsPdf AutoTable将动态数据打印到PDF中,但未能做到这一点.我搜索了许多站点,但没有人没有提到行数据中的动态数据.所以这是我的问题,是否有办法将Dynamic数据放入表行,是否可以澄清一下.注意:[这里没有使用HTML将数据存储到Pdf中,我直接从js获得了数据].

Am trying to print the dynamic data into the PDF using jsPdf AutoTable .But am failed to do that. I searched in many site's but no one didn't said about dynamic data into the Row's. So here my question is , Is there any way to get the Dynamic data into the table row's if it so can some one clarify me pls . Note : [ Here am not using HTML to store the Data into the Pdf, i got the data from the js directly ] .

this.print=function(){
        	{
        		
        		var mainData =this.printData(); // Here am getting Full Json data Here
        		var steps = mainData.steps;   // From that data am Separating what i need
        		var criticality = mainData.criticality;
        		var categories = mainData.categories;
        		var checkup = mainData.checkup;
        		
            // This is For to Take the Steps Data alone
               $scope.getSteps = function(steps) {
                   var data = [];
                   for (var i = steps.length; i-- > 0;) {
                     data.push(steps[i].name+"\n"+"\n");
                   }
                   return data;
                 }
               
                     // Like wise am getting every single object data's 
                  $scope.getNumbersOfSubSteps = function(steps) {
                   var data = 0;
                   for (var i = 0 ; i < steps.length; i++) {
                     for (var j = 0; j<steps[i].steps.length; j++) {
                      }
                     data = j ;
                   }
                   return data;
                 }

                 // this is for Sub Proceeses
                 $scope.getSubProcesses = function(steps) {
                   var data = [];
                   for (var i = 0 ; i < steps.length; i++) {
                      for (var j = 0; j<steps[i].steps.length; j++) {
                          data.push(steps[i].steps[j].name+"\n");                  
                     }
                   }
                   return data;
                 }
                 
                  $scope.getCategories = function(categories) {
                   var data = [];
                   for (var i = categories.length; i-- > 0;) {
                     data.push(categories[i].name+"\n");
                   }
                   return data;
                 } 
                  
                  $scope.getCriticality = function(criticality) {
                   var data = [];
                   for (var i = criticality.length; i-- > 0;) {
                     data.push(criticality[i].name+"\n");
                   }
                   return data;
                 }
         
                 // Pdf Print Function Begins 
                  
                var columns = ["ProcessDescription", "Steps", "#ofSubProcesses", "SubSteps","Category","Criticality","CheckUp"];
                var processDescription =mainData.description;
                var processes= $scope.getSteps(steps);
                var NoOfSubProcess = $scope.getNumbersOfSubSteps(steps);
                var subProcesses = $scope.getSubProcesses(steps);
                console.log('Subprocsses length',subProcesses);
                var categories = $scope.getCategories(categories);
                var criticality = $scope.getCriticality(criticality);
                
                // The Problem Begins here , Am struggling to Get the Separate data's here !
                var rows = [
                                    [processDescription,processes,NoOfSubProcess,subProcesses,categories,criticality]
                            
                             ];
                
                var pdfsize='a1';
                var doc = new jsPDF('p', 'pt',pdfsize);
     
                doc.autoTable(columns, rows, {
                	theme: 'striped', // 'striped', 'grid' or 'plain'
                	styles: {
                	      overflow: 'linebreak',
                	      columnWidth: 'wrap'
                	    },
                	    beforePageContent: function(data) {
                	        doc.text("Process Name :"+mainData.name, 40, 30);
                	    },
                    columnStyles: {
                      1: {columnWidth: 'auto'}
                    }
                  });

                  doc.save(mainData.name+ pdfsize +".pdf");
            }
          	
       	
          
        };

推荐答案

您将需要替换以下内容:

You will need to replace this:

var rows = [
    [processDescription,processes,NoOfSubProcess,subProcesses,categories,criticality]
];

具有这样的内容:

var rows = [];
for (var k = 0 ; k < processes.length; k++) {
    rows.push([
        processDescription,
        processes[k],
        NoOfSubProcess,
        subProcesses[k],
        categories[k],
        criticality[k]
    ]);
};

rows参数应该是一个数组数组.如果我理解正确的话,你所输入的基本上是一个数组的一个数组.

The rows parameter should be an array of arrays. What you are putting in there is basically an array of an array of arrays if I understood correctly.

这篇关于在jsPdf AutoTable中尝试动态数据时遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆