Hi @Ashok Kumar,
how can we stop to print one particular column on pdf download (I mean only allow download the Col__A and Col_B td data
You can find the table header by row.find("TH").eq(0).html()
. Then find the data through row.find("TD").eq(0).html()
, and specify the index of eq(index) according to the row you need. For details, you can refer to the code below.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js" rel="stylesheet"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js" rel="stylesheet"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<link rel="Stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" />
<script>
function Export() {
var res = new Array();
$("#stockalloctbl_1 tbody tr").each(function () {
var row = $(this);
var data = {};
data.Col_A = row.find("TD").eq(0).html();
data.Col_B = row.find("TD").eq(1).html();
res.push(data);
});
var re = [];
$("#stockalloctbl_1 thead tr").each(function () {
var row = $(this);
var A = row.find("TH").eq(0).html();
var B = row.find("TH").eq(1).html();
re.push(A, B);
});
var docDefinition = {
content: [
{ text: 'Dynamic parts', style: 'header' },
table(res, re)
]
}
// download the PDF
pdfMake.createPdf(docDefinition).download('optionalName.pdf');
}
function buildTableBody(data, columns) {
var body = [];
body.push(columns);
data.forEach(function (row) {
var dataRow = [];
columns.forEach(function (column) {
dataRow.push(row[column].toString());
})
body.push(dataRow);
});
return body;
}
function table(data, columns) {
return {
table: {
headerRows: 1,
widths: ['*', 'auto', 100],
body: buildTableBody(data, columns)
}
};
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="tablediv">
<table id="stockalloctbl_1">
<thead>
<tr role="row">
<th>Col_A</th>
<th>Col_B</th>
<th>Col_C</th>
</tr>
</thead>
<tbody>
<tr>
<td>data1</td>
<td>data2</td>
<td>data3</td>
</tr>
<tr>
<td>gama1</td>
<td>gama2</td>
<td>gama3</td>
</tr>
<tr>
<td>vega1</td>
<td>vega2</td>
<td>vega3</td>
</tr>
<tr>
<td>theta1</td>
<td>theta2</td>
<td>theta3</td>
</tr>
</tbody>
</table>
<input type="button" value="Export" onclick="Export()" />
</div>
</form>
</body>
</html>
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.