Can we get blob or any kind of FormData o file while we export

Can we get blob or any kind of FormData o file while we export

nayanmiyatranayanmiyatra Posts: 5Questions: 1Answers: 0

I'm using datatable in one of my angular project, it's working fine but I want the Blob or Any kind of FormData of file that we exported.

Is that possible to do with datatable in Angular?

this is the code I'm using for exports.

this.dtOptions = {
      dom: 'Bfrtip',
      buttons: [
        {
          extend: 'pdf',
          exportOptions: {
            columns: [0]
          },
          header: true,
          footer: true,
          title: 'Project Type Information',
          customize: function (doc) {
            doc.pageMargins = [30, 30, 30, 30];
            doc.defaultStyle.fontSize = 6;
            doc.styles.tableHeader.fontSize = 6;
            doc.styles.tableFooter.fontSize = 6;
            doc.styles.title.fontSize = 9;
            doc.styles.title.alignment = 'left';
            // doc.defaultStyle.alignment = 'right';

            // Create a footer
            doc['footer'] = (function (page, pages) {
              return {
                columns: [
                  {
                    // This is the right column
                    alignment: 'center',
                    text: 'IFM360 Program Management Module',
                  },
                  // {
                  //   // This is the right column
                  //   alignment: 'right',
                  //   text: ['page ', { text: page.toString() }, ' of ', { text: pages.toString() }],
                  // }
                ],
                // margin: [10, 0]
              }
            });

            // Create a Header
            doc['header'] = (function (page, pages) {
              return {
                columns: [
                  // {
                  //   // 'This is your left footer column',
                  //   alignment: 'left',
                  //   // fontSize: 8,
                  //   // text: [
                  //   //   'Program: ', pNo + ' / ' + pName + '\n'
                  //   //   + 'Project: ', projectNo + ' / ' + projectName],
                  //   // margin: [0, 10]
                  // },
                  {
                    // This is the right column
                    alignment: 'right',
                    text: [runDate + '\n' + 'Page ', { text: page.toString() }, ' of ', { text: pages.toString() }],
                    margin: [0, 10]
                  }
                ],
                margin: [30, 5]
              }
            });
            // Styling the table: create style object
            var objLayout = {};
            // Horizontal line thickness
            objLayout['hLineWidth'] = function (i) { return .5; };
            // Vertikal line thickness
            objLayout['vLineWidth'] = function (i) { return .5; };
            // Horizontal line color
            objLayout['hLineColor'] = function (i) { return '#aaa'; };
            // Vertical line color
            objLayout['vLineColor'] = function (i) { return '#aaa'; };
            // Left padding of the cell
            objLayout['paddingLeft'] = function (i) { return 4; };
            // Right padding of the cell
            objLayout['paddingRight'] = function (i) { return 4; };
            // Inject the object in the document
            doc.content[1].layout = objLayout;
          }
        },
        {
          extend: 'csv',
          exportOptions: {
            columns: [0]
          },
        },
        {
          extend: 'excel',
          title: 'Project Type',
          exportOptions: {
            columns: [0]
          },
          customize: function (xlsx) {
            $(xlsx.xl["styles.xml"])
              .find('numFmt[numFmtId="164"]')
              .attr('formatCode', '[$$-en-AU]#,##0.00;[Red]-[$$-en-AU]#,##0.00');
          },
        },
        {
          extend: 'copy',
          exportOptions: {
            columns: [0]
          },
        },
        {
          extend: 'print',
          exportOptions: {
            columns: [0]
          },
        },
        {
          extends:'email'
        }
      ],
      pagingType: 'full_numbers',
      pageLength: 10,
      initComplete: function () {
        var $buttons = $('.dt-buttons').hide();
        $('#exportLink').on('change', function () {
          var DropdownList = (document.getElementById("exportLink")) as HTMLSelectElement;
          if (DropdownList.selectedIndex != 0) {
            var btnClass = $(this).find(":selected")[0].id
              ? '.buttons-' + $(this).find(":selected")[0].id
              : null;
            if (btnClass) { $buttons.find(btnClass).click() };

            setTimeout(() => {
              DropdownList.selectedIndex = 0;
            }, 1000);
          }
        });
      }
    };

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    No, I'm afraid there is no option in the Buttons export functions for getting the resulting blob at this time. This is the part of the code (for PDF at least - the others would be similar) that you'd need to add a callback to add that ability.

    Out of interest, what do you want to do with the Blob if not download it?

    Allan

Sign In or Register to comment.