New to Telerik UI for ASP.NET MVC? Download free 30-day trial

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

  1. Hide the columns by using the hideColumn method within the pdfExport event handler.
  2. 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

In this article