This is a migrated thread and some comments may be shown as answers.

Export to excel hierarchical grid/ hidden column

8 Answers 644 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shahinez
Top achievements
Rank 1
Shahinez asked on 07 Aug 2017, 11:01 AM

Hello , 

I had a hierarchical  grid and I want to export it to excel (JavaScript ) 

The file is generated successfully but only the principal grid is exported.
Also I want to export hidden column.

Thank you for your prompt reply

8 Answers, 1 is accepted

Sort by
1
Boyan Dimitrov
Telerik team
answered on 09 Aug 2017, 07:47 AM

Hello,

I would suggest to take a look at the Export Detail Grids how-to article - the example demonstrates how to export detail Grids to Excel and merge their workbooks with the master Grid workbook.

As for exporting initially hidden columns I would suggest to take a look at the http://dojo.telerik.com/UJUcU example. 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Jorge
Top achievements
Rank 1
commented on 05 May 2021, 06:19 PM

Thank you Boyan!. It works for me.
0
Shahinez
Top achievements
Rank 1
answered on 09 Aug 2017, 08:44 AM

Hello , 

 

Thank you for the code but I realised that hen I have a empty column, It's not exported , 

    <script type="text/jscript">
        $(document).ready(function () {
            var element = $("#grid").kendoGrid({
                excel:
                {
                    allPages: true,
                    fileName: "clients.xlsx",
                    proxyURL: "/save",
                    filterable: true
                },
                toolbar:
                [
                    { name: "excel", text: "Export to excel" }
                ],
                columns:
                [
                    { field: "Code_Client" },
                    { field: "Nom_Client"},
                    { field: "Groupe" },
                    { field: "Cote" },
                    { field: "Marche" },
                    { field: "Refere" ,hidden: true},
                    { field: "Nb_Employe" ,hidden: true},
                    { field: "Ca" ,hidden: true},
                    { field: "Type",hidden: true },
                    { field: " Commentaires" ,hidden: true},
                    { field: "Sous_Secteur" ,hidden: true},
                    { field: "Contact" ,hidden: true},
                    { field: "Adresse",hidden: true },
                    { field: "Téléphone" ,hidden: true},
                    { command: ["edit", "destroy"], title: " ", width: "170px" }
                ],
                editable: "popup",
                height: 550,                       
                dataSource:
                {
                    transport:
                    {
                        read: {  url: "api/Clients", dataType: 'json'},
                      
                    },
                   schema: {
                    
                        total: "total",
                        fields: {
                          Code_Client: { type: "string" },
                          Nom_Client: { type: "string" },
                          Groupe: { type: "string" },
                          Cote: { type: "Boolean" },
                          Marche: { type: "string" },
                          Refere: { type: "string" },
                            Nb_Employe: { type: "string" },
                            Ca: { type: "string" },
                            Type: { type: "string" },
                            Commentaires: { type: "string" },
                            Sous_Secteur: { type: "string" },
                            Contact: { type: "string" },
                            Adresse: { type: "string" },
                            Téléphone : { type: "string" }
                                }
                      
                      },
                },
                groupable: true,
                  sortable: true,
                  selectable: "multiple",
                  reorderable: true,
                  resizable: true,
                  sortable: true,
                reorderable: true,
                 excelExport: excelExport,
               
                columnMenu: true,
                  pageable: {
                        refresh: true,
                        pageSizes: true,
                        previousNext: true,
                        info: true
                    },
        });
     });
 
        var exportFlag = false;
 
function excelExport(e) {
  if (!exportFlag) {
    e.sender.showColumn(1);
    e.preventDefault();
    exportFlag = true;
    setTimeout(function () {
      e.sender.saveAsExcel();
    });
  }
}
    </script>

 

This is my code, 

 

thank you in advance,

0
Boyan Dimitrov
Telerik team
answered on 11 Aug 2017, 07:42 AM

Hello Shahinez,

I am not sure that I understand the current scenario here - an empty column is a column without any data or a hidden column? Could it be possible to send the response from the server in order to replicate the problem? Any additional information will be very helpful. 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Shahinez
Top achievements
Rank 1
answered on 14 Aug 2017, 09:44 AM

Hello, 

In my case a hidden column could be empty.

Also when applying the code you have provided for me , certains column disappear after extracting to excel and appear again only if I refresh the page

I extract data from the DATABASE with the code below.

public List <Models.Clients> Get()
        {
            var client = from c in _context.Clients
                          select new Models.Clients
                           
                           {
                                     
                          Code_Client = (String)c.Code_Client ,
                          Nom_Client = (String)c.Nom_Client,
                          Groupe = (String)c.Groupe,
                          Secteur = (String)c.Secteur,
                          Marche = (String)c.Marche,
                          Nb_Employe = (String)c.Nb_Employe,
                          Ca = (String)c.Ca,
                          Type = (String)c.Type,
                          Commentaires = (String)c.Commentaires,
                          Sous_Secteur = (String)c.Sous_Secteur,
                          Contact = (String)c.Contact,
                          Adresse = (String)c.Adresse,
                          Téléphone = (String)c.Téléphone   ,
                            Cote = (bool) c.Cote,
                            Refere = (bool) c.Refere
                       };
                           
                      
            return client.ToList();
        }     
0
Boyan Dimitrov
Telerik team
answered on 16 Aug 2017, 07:15 AM

Hello Shahinez,

After reviewing the code in your previous post I can see that after the excel export the hidden columns are not hidden. The approach shows how to show the hidden columns just for the excel export and then hide them again. Please refer to the code snippet that should be used: 

var exportFlag = false;
 
        function excelExport(e) {
          if (!exportFlag) {
            e.sender.showColumn(1);
            e.preventDefault();
            exportFlag = true;
            setTimeout(function () {
              e.sender.saveAsExcel();
            });
          } else {
            e.sender.hideColumn(1);
            exportFlag = false;
          }
        }

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Anton Mironov
Telerik team
answered on 07 May 2021, 10:57 AM

Hello Shahinez,

Thank you for the details provided.

In order to include hidden columns in the Excel export, I would recommend using the implementation from the following knowledge base article:

Give a try to the implementation above and let me know if further assistance is needed.

 

Kind Regards,
Anton Mironov
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Jorge
Top achievements
Rank 1
commented on 07 May 2021, 01:46 PM

Anton,

I tried your suggestion but it get the following error
Uncaught TypeError: Cannot read property 'bind' of undefined

My version is 2021.1.224
0
Anton Mironov
Telerik team
answered on 11 May 2021, 08:46 AM

Hi Jorge,

Thank you for the details provided.

The issue is caused because you are trying to get the Grid before its initialization.

Use the pointed script in a "document.ready" scope and observe the result.

 

Best Regards,
Anton Mironov
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Jorge
Top achievements
Rank 1
commented on 11 May 2021, 07:11 PM

Anton
It did not work because my grid does not populate on document.ready function. My grid is dynamic based on a dropdownlist value. I needed to create a method to be called every time my grid is generated and now it works!!!
Thank you
0
Anton Mironov
Telerik team
answered on 13 May 2021, 12:28 PM

Hello Jorge,

I am glad to hear that the issue you were facing is now resolved. Actually, I was talking about getting the instance of the Grid, not populating it.

I confirm that the approach you made is the recommended one.

If any further assistance is needed, do not hesitate to contact me and the team.

 

Bets Regards,
Anton Mironov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Shahinez
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Shahinez
Top achievements
Rank 1
Anton Mironov
Telerik team
Share this question
or