Skip to Content
0

PDF Download using JSON model

Oct 24, 2017 at 06:44 AM

44

avatar image
Former Member

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)
10 |10000 characters needed characters left characters exceeded

Hi,

Why you are reading indices? What you're trying to do here?

var filteredIndices =table.getBinding().aIndices;
0
Former Member

Hi Irfan,

I am using it to get the sorted content from the table.

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jun Wu Oct 27, 2017 at 12:18 AM
0
table.getBinding("items")//if you are using sap.m.Table
Share
10 |10000 characters needed characters left characters exceeded