We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom Print / PDF export template for Grid

Hi,

I have a grid and is working fine . My requirement is i want to print / export pdf the grid data in a custom template.

When i view it should be exactly like a grid with all Grid features like Sort / Filter etc.
WHen i click print/ Export PDF , it should render the output in a custom view..

Can you help or provide any sample code to achieve this.

Thanks for your support in advance,
Regards

Haneef


7 Replies

SA Saravanan Arunachalam Syncfusion Team February 2, 2017 01:46 PM UTC

Hi Haneef, 
Thanks for contacting Syncfusion’s support. 
Could you please provide the below details to achieve your requirement? 
1.       What did you mean the custom template on your query? 
2.       Confirm whether you need to include the column template or export the Grid with customized template on pdf document? 
Regards, 
Saravanan A. 



HP Haneef Puttur February 2, 2017 01:52 PM UTC

Hi,
Basically i have a grid which contains data in 8 different columns. When i click export pdf it should display in a format which is basically a coupon with predefined format. 

On the other words the data which is in single row in grid will be split into 4 rows with 2 columns [ Like a Coupon / Label ]

So i am looking for export the Grid with customized template on pdf document.

Thanks in advance for your valuable time and support

Regards

Haneef



PV Prakash Viswanathan Syncfusion Team February 7, 2017 01:30 PM UTC

Hi Haneef, 

Thanks for the update. We have created sample to achieve your requirement, please find the attached sample below, 

Please let us know if you need any further assistance in customizing the sample. 

Regards, 
Prakash V. 



HP Haneef Puttur replied to Prakash Viswanathan February 8, 2017 06:43 AM UTC

Hi Haneef, 

Thanks for the update. We have created sample to achieve your requirement, please find the attached sample below, 

Please let us know if you need any further assistance in customizing the sample. 

Regards, 
Prakash V. 


Dear Sir,
Thanks for the help.  It serves my purpose 50%.

I have 100 records in my grid. After I apply some filter i get 20 records. However when I export using your code it exports the entire 100 records and not the 20 records.  
If i using the default export code it export only filtered 20 records.

I think the code you have sent not considering the filter.

Can you help  on this please.

Regards

Haneef


SA Saravanan Arunachalam Syncfusion Team February 9, 2017 01:12 PM UTC

Hi Haneef, 
We are sorry for the inconvenience. 
We have achieved your requirement by performing DataOperation (filter & sorting) on the server side based on the GridModel property and please refer to the below code example. 
@(Html.EJ().Grid<object>("Filtering") 
        . . . 
        .AllowFiltering() 
        .AllowSorting() 
) 
 
public void ExportToPdf(string GridModel, string args) 
        { 
            PdfExport exp = new PdfExport(); 
            var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList(); //Get the Datasource 
            GridProperties GridProp = ConvertGridObject(GridModel); //Converted as a GridProperties 
            DataOperations dataOp = new DataOperations(); 
            var FilteredData = dataOp.Execute(DataSource, GridProp); //Perform data operation to Filter or sort the datasource 
            JavaScriptSerializer serializer = new JavaScriptSerializer(); 
            IEnumerable div = (IEnumerable)serializer.Deserialize(GridModel, typeof(IEnumerable)); 
 
            Dictionary<string, dynamic> gridParams = serializer.Deserialize<Dictionary<string, dynamic>>(GridModel); 
 
            GridProperties gridProp = new GridProperties(); 
            List<OrdersView> ListData = FilteredData.Cast<OrdersView>().ToList(); 
            DrawGrid(ListData, gridParams); 
        } 
private GridProperties ConvertGridObject(string gridProperty) 
        { 
            JavaScriptSerializer serializer = new JavaScriptSerializer(); 
            IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable)); 
            GridProperties gridProp = new GridProperties(); 
            foreach (KeyValuePair<string, object> ds in div) 
            { 
                var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); 
                if (property != null) 
                { 
                    Type type = property.PropertyType; 
                    string serialize = serializer.Serialize(ds.Value); 
                    object value = serializer.Deserialize(serialize, type); 
                    property.SetValue(gridProp, value, null); 
                } 
            } 
            return gridProp; 
        } 
   
And we have created a sample that can be downloaded from the below link. 
Regards, 
Saravanan A. 



HP Haneef Puttur February 10, 2017 08:19 AM UTC

Dear Sir,

Thanks for your quick support and a complete working solution.
Now my issue is resolved and I am able to export the data in a format which i need and also in a custom view.

Hereby I confirm that , my issue is resolved and thanks to your entire team for the great product and great support.
Regards

Haneef




SA Saravanan Arunachalam Syncfusion Team February 13, 2017 04:13 AM UTC

Hi Haneef,  
Thanks for your update.            
We are happy that the provided information helped you. 
Regards, 
Saravanan A. 


Loader.
Up arrow icon