代码之家  ›  专栏  ›  技术社区  ›  FullStackDeveloper

AngularJS ui网格导出为pdf-页码和pdf标题太左,但网格太右

  •  0
  • FullStackDeveloper  · 技术社区  · 7 年前

    http://ui-grid.info/docs/#/tutorial/206_exporting_data

    问题:

    我试图在网上搜索解决方案,但没有成功。这是我的网格选项设置:

    gridOptions = {
                showGridFooter: true,
                showFooter: false,
                enableSorting: true,
                multiSelect: false,
                enableFiltering: true,
                enableRowSelection: true,
                enableSelectAll: false,
                enableRowHeaderSelection: false,
                enableGridMenu: true,
                noUnselect: true,
                onRegisterApi: function (_gridApi) {
                    this.gridApi = _gridApi;
                },
                data: [],
                exporterCsvFilename: 'Report.csv',
                exporterPdfDefaultStyle: {fontSize: 9},
                exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
                exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
                exporterPdfHeader: { text: "Foo", style: 'headerStyle' },
                exporterPdfFooter: function ( currentPage, pageCount ) {
                    return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
                },
                exporterPdfCustomFormatter: function ( docDefinition ) {
                    docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
                    docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
                    return docDefinition;
                },
                exporterPdfOrientation: 'portrait',
                exporterPdfPageSize: 'LETTER',
                exporterPdfMaxGridWidth: 500,
                exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
            };
    

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   JoxieMedina    7 年前

    您需要在页眉和页脚样式中添加边距 gridOptions

    $scope.gridOptions = {
    ...
    exporterPdfTableStyle: {margin: [20, 20, 20, 20]},
    ...
    exporterPdfCustomFormatter: function ( docDefinition ) {
      docDefinition.styles.headerStyle = { margin: [30, 30, 30, 30],fontSize: 22, bold: true };
      docDefinition.styles.footerStyle = { margin: [30, 30, 30, 30],fontSize: 10, bold: true };
      return docDefinition;
    },
    ...