My name is Claudio, and in first place, sorry for my english, iam not good with this languaje. Ok, this is the thing... i try to export my webgrid to excel and pdf, but keeping the sorting and the filters. My webgrid with all the information is like this:
Add, i need to export like this:
when applying the filter and sorting
So, when i click in the respective image, i need to process the information and get the document whit the correct filter and sorting applied to my webgrid.
For PDF, i use the "Itext" Library. For excel, I have not done yet, as well as not doing so. I think the best thing will be converting to HTML and save it as ".xls"
The only way that works for me the PDF is sent to another page "cshtml" for URL anything missing relevant, and then on the new page redo the query to the database, and process information. As you will see, this way I can not get the filter and order applied
to the WebGrid, then the question is: how I can do this, when I press the "<a>" tag (images of Excel and PDF), and generate document according to filtering? Ideas?
I'm really staking on it, not as it working.
Hopefully someone can give me a hand with that. I will be attentive to your responses.
Greetings, and already thanks.
You can get the sorting and filtering information from the
WebGrid.SortDirection and
WebGrid.SortColumn properties. You can add these values to a querystring on your link:
Mike thank you very much for responding so quickly. Now comes a concern me: I have understood that it is not recommended to send a lot of information by URL, because the URL many times arrives with problems, then, in your opinion, is good to do that or there
will be a better option?
I will be attentive to your responses.
And again, thanks for everything.
Mike, when I try to send the "order and direction" of the WebGrid, according to the way you mention are not sent, which causes the problem to get. What do you think is the problem?
I'll be on top of your response. Greetings!
Look, this is my code on the page from which shipment (where I have the WebGrid):
var db= Database.Open("bdincubadora");
var sql = "SELECT DISTINCT * FROM proyecto, equipo_proyecto WHERE eliminacion_bool_proyecto LIKE @0 AND es_empresa LIKE @1 AND tipo_proyecto LIKE @2 AND proyecto.nombre_equipo=equipo_proyecto.nombre_equipo";
var eliminacion = "%" + Request["eliminacion"] + "%";
var esempresa = "%" + Request["empresa"] + "%";
var consultatipo = "%" + Request["consultatipo"] + "%";
var data = db.Query(sql, eliminacion, esempresa, consultatipo);
var grid = new WebGrid(source: data, defaultSort: "nombre_proyecto" , rowsPerPage: 20, canSort: true, canPage: true, ajaxUpdateContainerId: "grid");
So, the "SortColumn" still default column ("nombre_proyecto" from webgrid definition), and the "SortDirection" still "Ascending", so....the sort and order doens't work.
Aditional, i use the version 2.0.20710.0 of WebPages ( .NET 4.0 integrate).
skullsleep
Member
2 Points
14 Posts
WebGrid to Excel/PDF keeping the sorting and filter
Dec 12, 2012 10:50 PM|LINK
Hello everyone!
My name is Claudio, and in first place, sorry for my english, iam not good with this languaje. Ok, this is the thing... i try to export my webgrid to excel and pdf, but keeping the sorting and the filters. My webgrid with all the information is like this:
Add, i need to export like this:
when applying the filter and sorting
So, when i click in the respective image, i need to process the information and get the document whit the correct filter and sorting applied to my webgrid.
For PDF, i use the "Itext" Library. For excel, I have not done yet, as well as not doing so. I think the best thing will be converting to HTML and save it as ".xls"
The only way that works for me the PDF is sent to another page "cshtml" for URL anything missing relevant, and then on the new page redo the query to the database, and process information. As you will see, this way I can not get the filter and order applied to the WebGrid, then the question is: how I can do this, when I press the "<a>" tag (images of Excel and PDF), and generate document according to filtering? Ideas?
I'm really staking on it, not as it working.
Hopefully someone can give me a hand with that. I will be attentive to your responses.
Greetings, and already thanks.
Claudio
Mikesdotnett...
All-Star
154842 Points
19855 Posts
Moderator
MVP
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 13, 2012 05:15 AM|LINK
You can get the sorting and filtering information from the WebGrid.SortDirection and WebGrid.SortColumn properties. You can add these values to a querystring on your link:
You can add your filter information there as well:
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
skullsleep
Member
2 Points
14 Posts
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 13, 2012 04:42 PM|LINK
Mike thank you very much for responding so quickly. Now comes a concern me: I have understood that it is not recommended to send a lot of information by URL, because the URL many times arrives with problems, then, in your opinion, is good to do that or there will be a better option?
I will be attentive to your responses.
And again, thanks for everything.
Claudio
Mikesdotnett...
All-Star
154842 Points
19855 Posts
Moderator
MVP
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 13, 2012 06:10 PM|LINK
Google does it all the time. That's how it works. If it's good enough for Google, it will be good enough for you.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
skullsleep
Member
2 Points
14 Posts
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 13, 2012 06:25 PM|LINK
lol, you're right Mike, I'll try and tell you. And thanks again for everything! Greetings!
skullsleep
Member
2 Points
14 Posts
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 14, 2012 02:21 AM|LINK
Mike, when I try to send the "order and direction" of the WebGrid, according to the way you mention are not sent, which causes the problem to get. What do you think is the problem?
I'll be on top of your response. Greetings!
Mikesdotnett...
All-Star
154842 Points
19855 Posts
Moderator
MVP
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 14, 2012 04:56 AM|LINK
Are you using an Ajax update? If so, make sure that the link appears within the element designated as the ajaxUpdateContainer
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
skullsleep
Member
2 Points
14 Posts
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 14, 2012 11:53 PM|LINK
Mike, doesn't work.
Look, this is my code on the page from which shipment (where I have the WebGrid):
var db= Database.Open("bdincubadora"); var sql = "SELECT DISTINCT * FROM proyecto, equipo_proyecto WHERE eliminacion_bool_proyecto LIKE @0 AND es_empresa LIKE @1 AND tipo_proyecto LIKE @2 AND proyecto.nombre_equipo=equipo_proyecto.nombre_equipo"; var eliminacion = "%" + Request["eliminacion"] + "%"; var esempresa = "%" + Request["empresa"] + "%"; var consultatipo = "%" + Request["consultatipo"] + "%"; var data = db.Query(sql, eliminacion, esempresa, consultatipo); var grid = new WebGrid(source: data, defaultSort: "nombre_proyecto" , rowsPerPage: 20, canSort: true, canPage: true, ajaxUpdateContainerId: "grid");And my WebGrid Id this:
@grid.GetHtml( tableStyle: "webgrid", headerStyle: "webgrid-header", footerStyle: "webgrid-footer", alternatingRowStyle: "webgrid-alternating-row", rowStyle: "webgrid-row-style", columns: grid.Columns( grid.Column(format: (item) => item.Value.nombre_proyecto , header: "Nombre Proyecto",columnName: "nombre_proyecto", canSort: true),//Header to specify display header grid.Column(format: (item) => item.Value.tipo_proyecto , header: "Tipo",columnName: "tipo_proyecto", canSort: true), grid.Column(format: (item) => item.Value.nombre_equipo , header: "Equipo",columnName: "nombre_equipo", canSort: true), grid.Column(format: (item) => item.Value.fecha_ini_proyecto.ToString("dd/MM/yyyy") , header: "Fecha Creacion",columnName: "fecha_ini_proyecto", canSort: true), grid.Column(format: (item) => "Twitter: "+item.Value.tw_proyecto +"; " + "Correo: "+item.Value.email_equipo , header: "Contacto",columnName: "email_equipo", canSort: true), grid.Column("", style: "oculto", format:@<text>@item.id_proyecto</text>) ) )So, whit this information, i can't send the order and sorting from WebGrid.
This is my link that send the data:
with all this, nothing happens. Ideas Mike? I maybe wrong defined WebGrid, or something....i don't know. What is the problem?
I will be attentive to your response Mike.
PS: in my page where I get the data, I'm testing if it succeeded or failed, where I have:
@{ var ordendatos= Request.QueryString["sort"] ; var direccionordendatos = Request.QueryString["dir"] ; } <div> @ordendatos <br> @direccionordendatos </div>and..... nothing happens. The information doesn't show in the screen. :(
Mikesdotnett...
All-Star
154842 Points
19855 Posts
Moderator
MVP
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 15, 2012 06:46 AM|LINK
When you click your link, what does the URL in the browser address bar look like, and what version of Web Pages (WebMatrix) are you running?
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
skullsleep
Member
2 Points
14 Posts
Re: WebGrid to Excel/PDF keeping the sorting and filter
Dec 15, 2012 08:06 PM|LINK
Mike:
If i click in the link, and if i don't do the filters, order and sorting, the send URL is :
But , if i use all the filters, order by "equipo" and DESC sort, and the result is this:
So, the "SortColumn" still default column ("nombre_proyecto" from webgrid definition), and the "SortDirection" still "Ascending", so....the sort and order doens't work.
Aditional, i use the version 2.0.20710.0 of WebPages ( .NET 4.0 integrate).
What is the problem Mike? what do you think?
greetings and thanks for all the help.
Claudio