Excluding Columns from the Exported PDF File
Environment
Product | Grid for Progress® Telerik® UI for UI for ASP.NET MVC |
Description
How can I exclude certain columns from the exported PDF file in a Telerik UI for ASP.NET MVC Grid?
Solution
Using the k-pdf-export
Class and CSS
To hide a Grid column only during the PDF export, use a CSS rule and reduce the width of the target column to zero. This approach is implemented because the Kendo UI Drawing API adds the k-pdf-export
class on all elements of the exported content and you can target specific elements in the following way.
<style>
.k-pdf-export colgroup > col:nth-child(4) {
width:0; /* hides only the 4th column during PDF export */
}
</style>
For example refer to this Telerik REPL Project
Using the showColum()
and hideColumn()
Grid Methods
- Hide the columns by using the
hideColumn
method within thepdfExport
event handler. - When the export is done, display the hidden column by using the
showColumn
method.
<script>
var exportFlag = false;
function onPdfExport(e){
if (!exportFlag) {
e.sender.hideColumn(1);
e.preventDefault();
exportFlag = true;
e.sender.saveAsPDF().then(function(){
e.sender.showColumn(1);
exportFlag = false;
});
}
}
</script>
For example refer to this Telerik REPL Project
More ASP.NET MVC Grid Resources
See Also
- Telerik REPL: Excluding Columns from the Exported PDF File by Using
k-pdf-export
- Telerik REPL: Excluding Columns from the Exported PDF File by Using
showColumn
andhideColumn
- Client-Side API Reference of the Grid for ASP.NET MVC
- Server-Side API Reference of the Grid for ASP.NET MVC
- Telerik UI for ASP.NET MVC Breaking Changes
- Telerik UI for ASP.NET MVC Knowledge Base