Skip to Content
avatar image
Former Member

PDF Download using JSON model

Hi,

I need to download the filtered table content into a PDF file. I am using JSON model.

I am getting the below error.

capture.png

I am using the below code on click of the PDF button. Kindly help me with this.

onDownloadPdf: function() {
			var oModel1 = new sap.ui.model.json.JSONModel("model/material.json");
			this.getView().setModel(oModel1, "material");


			var columnsArray = [{
				title: "Material",
				key: "{material>Material}"
			}, {
				title: "Material Description",
				key: "{material>MaterialDescription}"
			}, {
				title: "Delivery Date",
				key: "{material>DeliveryDate}"
			}, {
				title: "Quantity",
				key: "{material>Quantity}"
			}, {
				title: "Factory Location",
				key: "{material>FactoryLocation}"
			}];
			var dataArray = [];
			var table = this.getView().byId("tableId");
			//Will give you list of indices after filter & sort 
			var filteredIndices = table.getBinding().aIndices;
			for (var index = 0; index < filteredIndices.length; index++) {
				dataArray.push("{material>/TableContent}" [filteredIndices[index]]);
			}
			var pdfName = "FilteredReport.pdf";
			var doc1 = new jsPDF('p', 'pt');
			doc1.setFontSize(12);
			doc1.autoTable(columnsArray, dataArray, {});
			doc1.save(pdfName);
		},
capture.png (28.5 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Oct 27, 2017 at 12:18 AM
    table.getBinding("items")//if you are using sap.m.Table
    Add comment
    10|10000 characters needed characters exceeded