Printing grid using custom template

Hi!

I have a grid with +15 columns and of course when printing the grid not all columns are visible. Is there a way to print correctly all the columns? Maybe using a template for each row (each row will be one page).


Thanks, regards!


17 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team October 26, 2017 04:00 PM UTC

Hi Daniel, 

Thanks for contacting Syncfusion support. 

Query: Trying to fit all columns on a page while print the Grid. 

We have analyzed your query and we are able to reproduce the reported issue. If the grid table width exceeds the paper size then the grid columns gets cut. So, if you need to print the grid data's in pdf format then we suggest you to use our PDF exporting feature and then print the file.  

Refer the online sample for pdf exporting and hep documentation. 



Regards, 
Thavasianand S. 



DA Daniel October 26, 2017 05:27 PM UTC

Hi!

Thanks for the reply, I tried to add the PDF export but I have problems... apparently is because in my grid I'm using foreign columns... How I can resolve this issue?



This is part of my view:



And my datasource:



Thanks, regards!


TS Thavasianand Sankaranarayanan Syncfusion Team October 27, 2017 03:30 PM UTC

Hi Daniel, 

When we export the grid with foreign key columns the dataSource type of the foreign key columns is passed as generic object to the export function. As we do not have support to export generic type list, a null exception is thrown 

We already discuss about the above mentioned issue in the following knowledge base documentation.  


We have prepared a sample and it can be downloadable from the below location. 


If you still face the same issue then please provide the following details for better assistance. 

  1. Share the your foreignKey column dataSource (maximum 5 records).
  2. Share the exception details with more information.
  
Regards, 
Thavasianand S. 



DA Daniel October 27, 2017 06:56 PM UTC

Hi!

Thanks for the reply but it didn´t work with documentation that you sent.

I think that is other problem because the datasource of the 3 foreignkey columns are not empty/null (these columns are Alumno, Ciclo and Grado):









I think that the error is because the datasource don´t have the field that is related by the foreign key. If you see, my key of one of the foreign columns is named AlumnoID but at the moment of export the process is searching the value Alumno that exist in another table:


This is the error:

System.ArgumentException occurred
  HResult=0x80070057
  Message='Nombre' is not a member of type 'EurekaVillaFeliz.Database.t_Pagos'
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

And the stacktrace:

[ArgumentException: 'Nombre' is not a member of type 'EurekaVillaFeliz.Database.t_Pagos']
   System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName) +2720549
   Syncfusion.Linq.QueryableExtensions.GetValueExpression(ParameterExpression paramExpression, String propertyName, Type sourceType) +660
   Syncfusion.Linq.QueryableExtensions.GetLambdaWithComplexPropertyNullCheck(IQueryable source, String propertyName, ParameterExpression paramExpression, Type sourceType) +449
   Syncfusion.Linq.QueryableExtensions.OrderBy(IQueryable source, String propertyName, Type sourceType) +55
   Syncfusion.JavaScript.DataSources.DataOperations.PerformSorting(IEnumerable dataSource, List`1 sortedColumns) +138
   Syncfusion.JavaScript.DataSources.DataOperations.Execute(IEnumerable dataSource, GridProperties property) +221
   Syncfusion.EJ.Export.GridPdfExport.ExecuteResult(GridProperties GridModel, Object dataSource) +275
   Syncfusion.EJ.Export.GridPdfExport.ExportHelper(GridProperties GridModel, Object dataSource) +618
   Syncfusion.EJ.Export.GridPdfExport.Export(GridProperties GridModel, Object dataSource, Boolean multipleExport) +16
   Syncfusion.EJ.Export.PdfExport.Export(GridProperties gridmaodel, Object datasource, String fileName, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, Boolean unicode, String theme, Boolean isAutoFit) +111
   Syncfusion.EJ.Export.PdfExport.Export(GridProperties gridmaodel, Object datasource, String fileName, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme) +32
   Syncfusion.EJ.Export.PdfExport.Export(GridProperties gridmaodel, IEnumerable datasource, String fileName, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme) +28
   EurekaVillaFeliz.Controllers.PagosController.ExportToPdf(String GridModel) in C:\Users\daniel.colunga\Downloads\Página Eureka\EurekaVillaFeliz\EurekaVillaFeliz\EurekaVillaFeliz\Controllers\PagosController.cs:187
   lambda_method(Closure , ControllerBase , Object[] ) +103
   System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +228
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9987157
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

If helps, this is the diagram of the DB:



Thanks, regards!



TS Thavasianand Sankaranarayanan Syncfusion Team October 30, 2017 04:24 PM UTC

Hi Daniel, 

We have analyzed your query and we are able to reproduce the reported issue from our end. While we sort the column “Nombre” which is not in the t_Pagos database in Grid. But the column “Nombre” which is in the foreignKey table t_Alumnos. This is not the recommended way to sort the column which is not in the main database(t_Pagos) in Grid. Because the column “Nombre” is not the dataSource t_Pagos. So, we suggest you to remove those lines for sorting the column “Nombre” column in main Grid. 

Regards, 
Thavasianand S. 



DA Daniel October 30, 2017 06:55 PM UTC

Hi!

Uhmmm... is there a way to print as PDF/Excel/Word with sorting fields that are foreign columns?  I really need the main grid to be sorted by these foreign columns and can be edited.

Also, I tried to remove code from view and controller only to check if works without the sorting but without success:

This is part of my view:




These are some code from my controller:





Stacktrace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Syncfusion.EJ.Export.GridPdfExport.GetSummaryValue(IQueryable items, SummaryType type, SummaryColumn dsSummary, String field) +314
   Syncfusion.EJ.Export.GridPdfExport.ProcessSummaryRow(IQueryable items, Boolean totalSummary) +545
   Syncfusion.EJ.Export.GridPdfExport.RenderRecord() +252
   Syncfusion.EJ.Export.GridPdfExport.ProcessGridContents() +136
   Syncfusion.EJ.Export.GridPdfExport.IterateElements() +406
   Syncfusion.EJ.Export.GridPdfExport.ExportHandler() +25
   Syncfusion.EJ.Export.GridPdfExport.ExecuteResult(GridProperties GridModel, Object dataSource) +366
   Syncfusion.EJ.Export.GridPdfExport.ExportHelper(GridProperties GridModel, Object dataSource) +618
   Syncfusion.EJ.Export.GridPdfExport.Export(GridProperties GridModel, Object dataSource, Boolean multipleExport) +16
   Syncfusion.EJ.Export.PdfExport.Export(GridProperties gridmaodel, Object datasource, String fileName, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, Boolean unicode, String theme, Boolean isAutoFit) +111
   Syncfusion.EJ.Export.PdfExport.Export(GridProperties gridmaodel, Object datasource, String fileName, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme) +32
   Syncfusion.EJ.Export.PdfExport.Export(GridProperties gridmaodel, IEnumerable datasource, String fileName, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme) +28
   EurekaVillaFeliz.Controllers.PagosController.ExportToPdf(String GridModel) in C:\Users\daniel.colunga\Downloads\Página Eureka\EurekaVillaFeliz\EurekaVillaFeliz\EurekaVillaFeliz\Controllers\PagosController.cs:187
   lambda_method(Closure , ControllerBase , Object[] ) +103
   System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +228
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9987157
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Thanks, regards!


TS Thavasianand Sankaranarayanan Syncfusion Team October 31, 2017 02:33 PM UTC

Hi Daniel, 

Thanks for your update. 

Query 1: Is there a way to print as PDF/Excel/Word with sorting fields that are foreign columns? And can be edited? 
 
According to your query that you want to have foreignKey column in Grid and you need to search that column based on the foreignKey value (FirstName) not with foreignKeyField (EmployeeID) value. So, that we suggest you to enable ForeignKeyAdaptor in your sample to search the Grid column values based on the foreignKey value (FirstName).  
 
Refer the help documentation for ForeignKey Adaptor 


Note: we can edit foreignKey column value in Grid and there is no restriction on editing with foreignKey column value. 
 
Query 2: Null reference exception issue. 
 
The mentioned issue will occurred when the columns bound to the Grid are not defined in the Grid dataSource. We have already discussed the same issue in following knowledge base document.  
 

Regards, 
Thavasianand S. 



DA Daniel November 1, 2017 05:29 PM UTC

Hi!

Thanks for your help, both documents helped me solve the issue and the things that were missing.

Now, as last, I have 2 more details:

* I want to export the data with the same functionality as from client with the "queryCellInfo" to change the background color a specific cell based on a specific hidden cell value. This is how it looks from client side:



And this is how looks at this moment as exported:



The last pending thing is hide the columns that are not necessary to show, how I can do this or how I can export the grid with the same functionality of the colors?

This is the querycellinfo javascript function:

    function queryCellInfo(args) {
        if (args.column.field == "blEne" && args.data.blEne) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blFeb" && args.data.blFeb) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blMar" && args.data.blMar) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blAbr" && args.data.blAbr) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blMay" && args.data.blMay) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blJun" && args.data.blJun) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blJul" && args.data.blJul) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blAgo" && args.data.blAgo) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blSep" && args.data.blSep) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blOct" && args.data.blOct) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blNov" && args.data.blNov) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blDic" && args.data.blDic) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blInscripcion" && args.data.blInscripcion) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blMaterialAseo" && args.data.blMaterialAseo) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blUtilesEscolares" && args.data.blUtilesEscolares) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blMaterialConsumo" && args.data.blMaterialConsumo) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blUniforme" && args.data.blUniforme) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blCredencial" && args.data.blCredencial) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }

        if (args.column.field == "blSeguro" && args.data.blSeguro) {
            $($(args.cell).closest("td").next()).css("backgroundColor", "yellow")
        }
    }
</script>

This is part of the configuration of the grid:



And from controller:





* The exporting file have other culture format (globalization) compared to the original data, how to maintein same culture for the export file?





Thanks, regards!



TS Thavasianand Sankaranarayanan Syncfusion Team November 2, 2017 10:10 AM UTC

Hi Daniel, 

Query 1: Do not show the hided in columns in exported file. 

We have analyzed your query and we suspect that you want to export the Grid without hidden columns. So, we suggest you to set false for IsHideColumnInclude while exporting the Grid. 

Refer the below code example. 


public void ExportToExcel(string GridModel) 
        { 
 
 
            ---- 
 
            exp1.Excelversion = ExcelVersion.Excel2010; 
 
            exp1.Theme = "flat-saffron"; 
 
            exp1.IsHideColumnIncude = false; // To hide the hided column in Grid exported file 
 
            exp.Export(obj, DataSource, exp1); 
            
 
        } 



Query 2: Need to show the exported file with color marked in Grid cell. 

We have already discuss about the above mention query in the following documentation link. 



Query 3: Exported file have the different culture in it. 

We have analyzed your query and we are unable to reproduce the reported issue “exported file have the different culture in money symbol” from our end.  

Please provide the following details for better assistance. 

  1. Essential Studio Version details.
  2. If possible reproduce the issue in the attached sample.
  3. Which culture that you required to show in Grid ?
 
We have prepared a sample for queries 2 & 3 and it can be downloadable from the below location. 


Regards, 
Thavasianand S. 



DA Daniel November 3, 2017 04:30 PM UTC

Hi!

Thanks for the example but it's not exactly that I commented in the last reply. I understand the explanation of the Query 1 and 2 from your reply but the problem that I have is that in client side I have a hidden column where these values (boolean values) have the functionality to change the background of another cell. Using part of your example, I attached a new one with the idea that I have in my original project:

* This is the general idea from the client side... there is a hidden column (in this case named verified) that based on the value this will change the color of the first cell of the same row:



I need to export to excel this same grid as it looks and the functionality of changing color cell based on that hidden column. The problem is if I don´t add that hidden column to the excel exportation I cannot use that column as conditional to change the color for the first cell of that row.

This is when I add the hidden column and use it to change the color of the first cell of the row (there are 7 columns):




This is when i don´t include the hidden column (there are 6 columns) and I cannot use the hidden column for conditional:



The final result that I need is the following (same view as in the grid in client side, without the verifed column)



The problem of the culture I already resolved but I don´t why happened  about the different simbols of the money (in the grid and in the exporting file). I only changed the locale to "es-MX" where I have the translation texts and in the grid and that resolves my problem of the culture.

Thanks, regards!


Attachment: SyncfusionMvcApplication40__Copy_5edbe54c.zip


TS Thavasianand Sankaranarayanan Syncfusion Team November 6, 2017 12:01 PM UTC

Hi Daniel, 

We have analyzed your query and we could see that you need to set the color of a cell for a column based on a hidden column. We suspect that you could not  get the value of the hidden column at server side during exporting. So we suggest you to get the value for the hidden column from the Grid datasource. 

Refer the below code example. 


public class GridController : Controller 
    { 
        // 
        // GET: /Grid/ 
        List<Orders> order = new List<Orders>(); 
 
        List<Orders> currentData = null; 
 
        public int count = 0; 
         
        --- 
 
        public void ExportToExcel(string GridModel) 
        { 
 
            ExcelExport exp = new ExcelExport(); 
            GridExcelExport exp1 = new GridExcelExport(); 
            BindDataSource(); 
            var DataSource = order; 
            currentData = order;  
             
            --- 
 
           exp1.IsHideColumnIncude = false; 
             
            exp.Export(obj, DataSource, exp1); 
        } 
 
        public void QueryCellInfo(object currentCell) 
        { 
            IRange range = (IRange)currentCell; 
            if (range.Column == 1) //Here it checks for the OrderID Column 
            { 
                if (currentData[count].Verified == true) //Here it checks the value of Hidden column "Verified(Hidden column)"                    {  
                        range.CellStyle.Color = Color.Yellow; 
                count++; 
            } 
        } 
    } 


We have modified the provided sample and it can be downloadable from the below location. 


Regards, 
Thavasianand S. 



DA Daniel November 6, 2017 04:55 PM UTC

Perfect! Nice idea, it works fine.

Thanks for all the help.

Regards!


TS Thavasianand Sankaranarayanan Syncfusion Team November 7, 2017 06:52 AM UTC

Hi Daniel, 
 
We are happy that the problem has been solved at your end. 
 
Please get back to us if you need any further assistance.  
 
Regards, 
Thavasianand S. 



DA Daniel November 9, 2017 11:02 PM UTC

Hi!

I found a problem with the last solution, if I filtering the data it did not export correctly the colors as in client side. This is without filtering in client side:


This is the exported file (that is correct):



But if I filter by something:



The export file is incorrect:



I already tried to correct this issue using the "range.row - 1" instead count but not always works:

        public void QueryCellInfo(object currentCell)
        {
            IRange range = (IRange)currentCell;

            //if (range.Column == 1) //Here it checks for the OrderID Column 
            //{
            //    if (currentData[count].Verified == true) //Here it checks the value of Hidden column "Verified(Hidden column)"                    {  
            //        range.CellStyle.Color = Color.Yellow;
            //    count++;
            //}

            if (range.Column == 1) //Here it checks for the OrderID Column 
            {
                if (currentData[range.Row - 1].Verified == true) //Here it checks the value of Hidden column "Verified(Hidden column)"                    {  
                    range.CellStyle.Color = Color.Yellow;
            }
        }





I attached the sample solution.

Regards!

Attachment: SyncfusionMvcApplication40__Copy_d562b33a.zip


TS Thavasianand Sankaranarayanan Syncfusion Team November 10, 2017 12:46 PM UTC

Hi Daniel, 

Sorry for inconvenience caused. 

We have analyzed your query and we are able to reproduce the reported issue from our end. Now we have modified the sample and it can be downloadable from the below location. 


Please add the yellow marked line to get the filtered record detail with background color changes in the exported file. 


public class GridController : Controller 
    { 
        // 
        // GET: /Grid/ 
        List<Orders> order = new List<Orders>(); 
        public int count = 0; 
        public static IEnumerable<Orders> DataSource2; 
 
        ----         
 
        public object UrlDataSource(DataManager dm) 
       { 
             
            ---- 
 
           if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            { 
                DataSource = ds.PerformWhereFilter(DataSource, dm.Where, dm.Where[0].Operator); 
                DataSource2 = (IEnumerable<Orders>)DataSource; 
                  
            } 
             
            ---- 
 
       } 
 
 
        public void ExportToExcel(string GridModel) 
        { 
 
            ExcelExport exp = new ExcelExport(); 
            GridExcelExport exp1 = new GridExcelExport(); 
            BindDataSource(); 
            var DataSource = order;  
            GridProperties obj = (GridProperties)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(GridProperties), GridModel); 
            obj.ServerExcelQueryCellInfo = QueryCellInfo; 
            exp1.Excelversion = ExcelVersion.Excel2010; 
            exp1.Theme = "flat-saffron"; 
            exp1.IsHideColumnIncude = false; 
            //exp1.IsHideColumnIncude = true; 
            exp.Export(obj, DataSource, exp1); 
        } 
 
        public void QueryCellInfo(object currentCell) 
        { 
            IRange range = (IRange)currentCell; 
            if (range.Column == 1) //Here it checks for the OrderID Column 
            { 
                if (DataSource2.ToList()[count].Verified == true) //Here it checks the value of Hidden column "Verified(Hidden column)"                    {  
                    range.CellStyle.Color = Color.Yellow; 
                count++; 
            } 
       } 
    } 


Regards, 
Thavasianand S. 



DA Daniel November 10, 2017 08:15 PM UTC

Hi! Perfect, that works... 

Thanks again, regards!


PK Prasanna Kumar Viswanathan Syncfusion Team November 13, 2017 04:38 AM UTC

Hi Daniel, 

We are happy to hear that your issue has been solved.  

Please let us know if you need any further assistance. 

Regards, 
Prasanna Kumar N.S.V 


Loader.
Up arrow icon