8 Answers, 1 is accepted
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
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,
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
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();
}
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
;
}
}
Boyan Dimitrov
Progress Telerik
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.
I tried your suggestion but it get the following error
Uncaught TypeError: Cannot read property 'bind' of undefined
My version is 2021.1.224
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.
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
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/.