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.
Unfortunately, activation email could not send to your email. Please try again.

Custom Print / PDF export template for Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

128611 Feb 1,2017 02:49 AM Feb 12,2017 11:13 PM ASP.NET MVC 7
loading
Tags: Grid
Haneef Puttur
Asked On February 1, 2017 02:49 AM

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


Saravanan Arunachalam [Syncfusion]
Replied On February 2, 2017 08:46 AM

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. 


Haneef Puttur
Replied On February 2, 2017 08:52 AM

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


Prakash Viswanathan [Syncfusion]
Replied On February 7, 2017 08:30 AM

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. 


Haneef Puttur
Replied On February 8, 2017 01:43 AM

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

Saravanan Arunachalam [Syncfusion]
Replied On February 9, 2017 08:12 AM

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. 


Haneef Puttur
Replied On February 10, 2017 03:19 AM

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



Saravanan Arunachalam [Syncfusion]
Replied On February 12, 2017 11:13 PM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;