2017-01-19 5 views
2

Ich arbeite an der Erstellung einer PDF und bis jetzt geht es gut, aber ich möchte einige bestimmte Zeilen zu fett. zum Beispiel siehe Bild: grid template from jspdf-autotable Wie kann ich zum Beispiel Zeile mit ID = 1 und ID = 3 fett machen? Unter meinem Code.Wie kann ich eine bestimmte Zeile fett machen?

function createPDF() { 
      if(vm.activeCompanyYear){ 
       var url = "/coci/report/registry/"+vm.activeCompanyYear; 

       DataApiService.callApi(url,null,"GET").then(function(reportData){ 

        if(reportData){ 
         var doc = new jsPDF('p', 'pt'); 
         var row = 45; 
         addPdfHeader(doc, row, ""); 
         doc.printingHeaderRow = true; 
         var columns = [ "Description", vm.activeCompanyYear,vm.activeCompanyYear-1, vm.activeCompanyYear-2,vm.activeCompanyYear-3,vm.activeCompanyYear-4,"% t.o.v.'13" ]; 

         var rows = []; 

         for(var j=0; j<reportData.length; j++){ 
          var obj = reportData[j]; 

          if (!obj.description) {obj.description = '';} 

          if (!obj.year5) {obj.year5 = '';} 

          if (!obj.year4) {obj.year4 = '';} 

          if (!obj.year3) {obj.year3 = '';} 

          if (!obj.year2) {obj.year2 = '';} 

          if (!obj.year1) {obj.year1 = '';} 

          if (!obj.delta) {obj.delta = '';} 


          /*TODO : Align data right in grid*/ 

          var singleRow = [obj.description,obj.year5,obj.year4,obj.year3,obj.year2,obj.year1,obj.delta]; 
          rows.push(singleRow); 

         }      

         doc.autoTable(columns, rows, { 
          theme : 'grid', 
          styles: { 
            halign: 'right', 
            }, 
          headerStyles: { 
             fillColor: [33, 150, 243], 
             halign:'center' 
          }, 
          margin : { 
           top : 100 
           }, 
          columnStyles:{ 
           0: {halign:'left'} 
          } 

         }); 


         vm.isLoading = false; 
         blockUI.stop(); 
         /* doc.save(); */ 
         vm.reportData = doc.output('datauristring'); 

        } 
       }); 
      } 
     } 

Antwort

3

So etwas sollte funktionieren:

doc.autoTable(cols, data, { 
    createdCell: function(cell, data) { 
    if (data.row.index === 0 || data.row.index === 2) { 
     cell.styles.fontStyle = 'bold'; 
    } 
    } 
}) 
+0

Das hat nicht funktioniert, es ist immer noch die gleiche –

+0

Meine schlecht, versuchen Mein aktualisierter Code. –

+0

Hallo Freund, ich habe es wie folgt versucht und es hat funktioniert: doc.autoTable (Spalten, Daten, { createdCell: Funktion (Zelle, Daten)) { if (data.row.index === 0 || data .row.index === 2) { cell.styles.fontStyle = 'fett'; } } }) –

0

Ich habe versucht, es wie folgt aus und es funktionierte:

doc.autoTable(cols, data, { createdCell: function(cell, data) { if (data.row.index === 0 || data.row.index === 2) { cell.styles.fontStyle = 'bold'; } } }) 
Verwandte Themen