可以以角度ui网格导出子网格

Mat*_*Eno 5 hierarchical subgrid angularjs angular-ui-grid pdfmake

我正在项目中使用来自http://ui-grid.info/的网格.我已经创建了一个分层网格,它可以很好地工作,但是当我进行导出时,它只从顶层网格导出数据.

这是设计的并且是网格的标准功能,因此我没有必要提出任何示例代码.来自http://ui-grid.info/docs/#/tutorial的任何例子都可以.

有没有办法导出子网格(最好是主网格和子网格一起出现在网格中)?

Mat*_*Eno 2

我设法让它工作,虽然如果我有时间,我会比我实际创建代码分支并正确执行它所做的更好一点,但考虑到时间限制,我得到的是工作顺利。

仅供参考,这是我最终让它执行我想要的操作的方法:

在我的网格选项中,我关闭了网格菜单中的 CSV 导出选项(因为我只实现了 PDF 的更改)。

我制作了exporter.js 的副本,将其命名为custom.exporter.js 并更改了我的引用以指向新文件。

在 custom.exporter.js 中,我复制了 getData 函数并将其命名为 getGridRows。getGridRows 与 getData 相同,只是它只返回行对象,而不返回获取列等的所有内容。目前,我正在对其进行编码以处理一组已知的列,因此我不需要所有这些。

我将 pdfExport 函数修改为如下:

pdfExport: function (grid, rowTypes, colTypes) {
              var self = this;

              var exportData = self.getGridRows(grid, rowTypes, colTypes);

              var docContent = [];

              $(exportData).each(function () {
                  docContent.push(
                      {
                          table: {
                              headerRows: 1,
                              widths: [70, 80, 150, 180],
                              body: [
                                [{ text: 'Job Raised', bold: true, fillColor: 'lightgray' }, { text: 'Job Number', bold: true, fillColor: 'lightgray' }, { text: 'Client', bold: true, fillColor: 'lightgray' }, { text: 'Job Title', bold: true, fillColor: 'lightgray' }],
                                [formattedDateTime(this.entity.JobDate,false), this.entity.JobNumber, this.entity.Client, this.entity.JobTitle],
                              ]
                          }
                      });
                  var subGridContentBody = [];
                  subGridContentBody.push([{ text: 'Defect', bold: true, fillColor: 'lightgray' }, { text: 'Vendor', bold: true, fillColor: 'lightgray' }, { text: 'Status', bold: true, fillColor: 'lightgray' }, { text: 'Sign off', bold: true, fillColor: 'lightgray' }]);
                  $(this.entity.Defects).each(function () {
                      subGridContentBody.push([this.DefectName, this.DefectVendor, this.DefectStatus, '']);
                  });
                  docContent.push({
                      table: {
                          headerRows: 1,
                          widths: [159, 150, 50, 121],
                          body: subGridContentBody
                      }
                  });
                  docContent.push({ text: '', margin: 15 });
              });

              var docDefinition = {
                  content:  docContent
              }


              if (self.isIE()) {
                  self.downloadPDF(grid.options.exporterPdfFilename, docDefinition);
              } else {
                  pdfMake.createPdf(docDefinition).open();
              }
          }
Run Code Online (Sandbox Code Playgroud)