Исправлено количество строк на странице с использованием pdfmake.js - PullRequest
0 голосов
/ 25 июня 2018

Определил собственные таблицы с помощью pdfmake.js.При печати я хочу, чтобы на странице содержалось 7 строк (исправлено). Я попытался отрегулировать высоту и ширину ячейки таблицы, чтобы она содержала 7 строк, однако, если данные в ячейке таблицы увеличиваются, страница накапливается с меньшим / большим количеством строк.,

// макет таблицы:

var tablelist={
      style: 'tableExample',
      table: {
          dontBreakRows: true,
           widths: [ 20,55,55,55,55,55,55,55,55,55,55,55,55],
          headerRows: 1,
          body: body

      },
      layout: {
        hLineWidth: function (i, node) {
          return (i === 0 || i === node.table.body.length) ? 1 : 1;
        },
        vLineWidth: function (i, node) {
          return (i === 0 || i === node.table.widths.length) ? 1: 1;
        },
        hLineColor: function (i, node) {
          return (i === 0 || i === node.table.body.length) ? 'gray' : 'gray';
        },
        vLineColor: function (i, node) {
          return (i === 0 || i === node.table.widths.length) ? 'gray' : 'gray';
        },

      },

    }
  return tablelist;
  }

// проталкивание заголовка таблицы и других данных в тело таблицы

  $scope.makePrintTable = function(){

var headers = {
    col_1:{ text: 'Day', style: 'tableHeader',rowSpan: 1, alignment: 'center',margin: [0, 8, 0, 0] },
    col_2:{ text: 'Date', style: 'tableHeader',rowSpan: 1, alignment: 'center',margin: [0, 8, 0, 0] },
    col_3:{ text: '0600-0800', style: 'tableHeader',rowSpan: 1, alignment: 'center',margin: [0, 8, 0, 0] },
    .
    .
    .//Similarly till col_13
      col_13:{ text: '1700-1800', style: 'tableHeader',rowSpan: 1, alignment: 'center' ,margin: [0, 8, 0, 0]},

    }

    body = [];
    var row = new Array();

    for (var key in headers) {
    row.push( headers[key] );   
      }
    body.push(row);


for ( var j=0 ; j< $scope.table.length; j++){
  var tableEach={ };
  tableEach= $scope.table[j];

  /*This for Genarating Object variables*/
  for (var i = 1; i < 3; i++) { 
     window["obj"+i] = new Object();
  }

  var row = new Array();
  var slNoValue = tableEach.slNo;

  /*This is for slNo  */
  obj1["text"] = slNoValue;
  obj1["style"]= "cellswidth"; 
  row.push(obj1);

   /*This is for Date  */
  var dateValue = new Date(tableEach.date);
  obj2["text"]= dateValue.getDate() + '-' + basicFormats.getMonthName(dateValue.getMonth() )+ '-' + dateValue.getFullYear()+','+ basicFormats.getDayName(dateValue.getDay());
  obj2["style"]= "cellswidth";
  row.push(obj2);

  /*This is for remaining columns (i ranges from 6 to 17 (time in 24hrs clock format) )  */
 for(var i=6 ; i<=17 ; i++){
   var obj={};

   var hourValue = "hour_"+i+"_"+(i+1)+"_value";
   var hourValueColor = "hour_"+i+"_"+(i+1)+"_"+"color_value";

      hourValue = ( tableEach["hour_"+i] == undefined ? '':(tableEach["hour_"+i]));
      hourValueColor =(tableEach["hour_"+i+"_colour"] == undefined ? '#ffffff':(tableEach["hour_"+i+"_colour"]));
      obj["text"] = hourValue;
      obj["fillColor"] = hourValueColor;
      obj["style"] = "cellswidth";
      row.push(obj);
      console.log(obj);

    }
  //  if( j!= 0 && j % 7 == 0){
  //   pageBreak : 'before'
  //  }
 } 
  body.push(row); 

}

};

// CSS для табличных ячеек

cellswidth  : {
        fontSize: 10,
        // color:'gray',
        bold: true,
        alignment: 'center',
        margin: [0, 12.55, 0, 12.75],

      },
...