Printing

4 Apr 20182 minutes to read

TreeGrid provides support to print the contents. To print the TreeGrid the print toolbar item must be added to ToolbarSettings.ToolbarItems property. The below code example shows how to enable print in TreeGrid.

  • CSHTML
  • @(Html.EJ().TreeGrid("TreeGrid")
        .ToolbarSettings(tool => {
            tool.ShowToolbar(true);
            tool.ToolbarItems(new List<TreeGridToolBarItems>(){
                TreeGridToolBarItems.Print        
            });        
        })
        )

    The below screen shot shows TreeGrid with printing enabled.

    The print preview window will be opened by clicking on this toolbar icon.

    It is possible to set the printMode in PageSettings property, to give printing preference, as to print current page alone or all the pages in case of paging enabled in TreeGrid. The following code example explains this.

  • CSHTML
  • @(Html.EJ().TreeGrid("TreeGrid")
        .AllowPaging(true)
        .PageSettings(pg=>pg.PrintMode(TreeGridPrintMode.CurrentPage))
        .ToolbarSettings(tool => {
            tool.ShowToolbar(true);
            tool.ToolbarItems(new List<TreeGridToolBarItems>(){
                TreeGridToolBarItems.Print        
            });        
        })
        )

    In this case only the visible records in the current page will be send to printing.

    BeforePrint Event

    BeforePrint event will be triggered once after printing initiated in TreeGrid. This event contains the treegrid element which is going to be printing. The following code explains this.

  • JS
  • @(Html.EJ().TreeGrid("TreeGrid")
        .ClientSideEvents(cl => {
            cl.BeforePrint("beforePrint");
        })
        .ToolbarSettings(tool => {
            tool.ShowToolbar(true);
            tool.ToolbarItems(new List < TreeGridToolBarItems > () {
                TreeGridToolBarItems.Print
            });
        })
    )
    <script>
        function beforePrint(args) {
            //will be triggered before printing the TreeGrid
        }
    </script>

    Click here to view the online demo sample Printing.