How to print all sfdatagrid rows

Hi!

Is there a way to print all rows from a sfDataGrid control when it's binded to a sfDataPagerControl?

3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team January 26, 2021 02:36 PM UTC

Hi Daniel Pérez,

Thank you for contacting Syncfusion support. 
Yes. You can print the all data row while SfDataGrid binded with SfDataPager control.  We have prepared the simple sample for your reference,

Sample Link: https://www.syncfusion.com/downloads/support/forum/161864/ze/Sample-1890572729

For more information related to Printing, please refer the below UG link,

UG Link: https://help.syncfusion.com/wpf/datagrid/printing

Please let us know, if you require further assistance on this. 
Regards,
Vijayarasan S



DP Daniel Pérez January 26, 2021 03:33 PM UTC

Thanks a lot

My issue was with the sfDataGrid, I enabled virtualization, but when I disabled, all the pages were printed.

Regards,

Daniel P.


VS Vijayarasan Sivanandham Syncfusion Team January 27, 2021 05:26 PM UTC

Hi Daniel Pérez,

Thanks for the update.

Based on provided information in SfDataGrid EnableDataVirtualization property enabled case improve the performance by only print the view records in SfDataGrid.

Your requirement can be achieved by override the GetSourceListForPrinting method in GridPrintManager in SfDataGrid. Please refer the below code snippet, 
private void btnPrint_Click(object sender, RoutedEventArgs e) 
{ 
            //print the data displayed in the DataGrid using SfDataGrid.Print method. 
            //sfDataGrid.Print(); 
 
            //Customize the Print settings in SfDataGrid 
            sfDataGrid.PrintSettings.PrintManagerBase = new CustomManagerBase(this.sfDataGrid); 
            sfDataGrid.PrintSettings.AllowPrintByDrawing = true; 
 
            //provides option to display print preview of SfDataGrid rows 
            sfDataGrid.ShowPrintPreview(); 
} 
 
public class CustomManagerBase : GridPrintManager 
{ 
        public SfDataGrid DataGrid; 
 
        internal IList source; 
 
        public CustomManagerBase(SfDataGrid grid) : base(grid) 
        { 
            DataGrid = grid; 
        } 
 
        private int GetUnBoundRowCount(UnBoundRowsPosition position, bool isbelowsummary) 
        { 
            int count = 0; 
 
            if (position == UnBoundRowsPosition.Top && !isbelowsummary) 
                count = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Top, false); 
            else if (position == UnBoundRowsPosition.Top && isbelowsummary) 
                count = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Top, true); 
            else if (position == UnBoundRowsPosition.Bottom && isbelowsummary) 
                count = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Bottom, true); 
            else if (position == UnBoundRowsPosition.Bottom && !isbelowsummary) 
                count = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Bottom, false); 
 
            return count; 
        } 
        
 
        protected override IList GetSourceListForPrinting() 
        { 
            var source = (View as PagedCollectionView).GetInternalList(); 
            List<object> OrderedSource = new List<object>(); 
 
            if (GetUnBoundRowCount(UnBoundRowsPosition.Top, false) > 0) 
            { 
                foreach (var row in dataGrid.UnBoundRows.Where(r => r.Position == UnBoundRowsPosition.Top && !r.ShowBelowSummary)) 
                    OrderedSource.Add(row); 
            } 
 
            if (GetTableSummaryList(TableSummaryRowPosition.Top).Count > 0) 
            { 
                foreach (var item in GetTableSummaryList(TableSummaryRowPosition.Top)) 
                    OrderedSource.Add(item); 
            } 
 
            if (GetUnBoundRowCount(UnBoundRowsPosition.Top, true) > 0) 
            { 
                foreach (var row in dataGrid.UnBoundRows.Where(r => r.Position == UnBoundRowsPosition.Top && r.ShowBelowSummary)) 
                    OrderedSource.Add(row); 
            } 
 
            foreach (var item in source) 
                OrderedSource.Add(item); 
 
            if (GetUnBoundRowCount(UnBoundRowsPosition.Bottom, false) > 0) 
            { 
                foreach (var row in dataGrid.UnBoundRows.Where(r => r.Position == UnBoundRowsPosition.Bottom && !r.ShowBelowSummary)) 
                    OrderedSource.Add(row); 
            } 
 
            if (GetTableSummaryList(TableSummaryRowPosition.Bottom).Count > 0) 
            { 
                foreach (var item in GetTableSummaryList(TableSummaryRowPosition.Bottom)) 
                    OrderedSource.Add(item); 
            } 
 
            if (GetUnBoundRowCount(UnBoundRowsPosition.Bottom, true) > 0) 
            { 
                foreach (var row in dataGrid.UnBoundRows.Where(r => r.Position == UnBoundRowsPosition.Bottom && r.ShowBelowSummary)) 
                    OrderedSource.Add(row); 
            } 
 
            return OrderedSource; 
        } 
} 
Please let us know, if you require further assistance on this. 
Regards,
Vijayarasan S




Marked as answer
Loader.
Up arrow icon