Oct 11, 2010, 5:31 PM
[CLOSED] Export Data To Excel in Remote Paging GridPanel
Hi,
I Wish to Export Data to Excel in Remote Paging and Sort GridPanel.
I try to use this sample:
https://examples1.ext.net/#/GridPane...Data_PostBack/
But it does not work because of the Remote Paging and Sort:
Data Source:
How to solve this problem?
I Wish to Export Data to Excel in Remote Paging and Sort GridPanel.
I try to use this sample:
https://examples1.ext.net/#/GridPane...Data_PostBack/
But it does not work because of the Remote Paging and Sort:
Data Source:
<ext:Store ID="StorePesquisaLinhaCredito" runat="server" OnRefreshData="StorePesquisaLinhaCredito_Refresh"
RemoteSort="true">
<Proxy>
<ext:PageProxy />
</Proxy>
<Reader>
<ext:JsonReader IDProperty="Numero">
<Fields>
<ext:RecordField Name="Numero" />
<ext:RecordField Name="Sigla" />
<ext:RecordField Name="Descricao" />
<ext:RecordField Name="OrigemRecurso" ServerMapping="OrigemRecurso.DescricaoCompleta" />
<ext:RecordField Name="GestaoCredito" ServerMapping="GestaoCredito.DescricaoCompleta" />
</Fields>
</ext:JsonReader>
</Reader>
<AutoLoadParams>
<ext:Parameter Name="start" Value="0" Mode="Raw" />
<ext:Parameter Name="limit" Value="10" Mode="Raw" />
</AutoLoadParams>
</ext:Store>
GridPanel:<ext:GridPanel ID="grdPesquisaLinhaCredito" runat="server" StoreID="StorePesquisaLinhaCredito"
AutoExpandColumn="Descricao" StripeRows="true">
<TopBar>
<pd:BarraComandos runat="server" ID="barraGrid" Height="25" />
</TopBar>
<ColumnModel runat="server">
<Columns>
<ext:Column ColumnID="Numero" Header="Número" Width="100" Sortable="true" DataIndex="Numero" />
<ext:Column ColumnID="Sigla" Header="Sigla" Width="100" Sortable="true" DataIndex="Sigla" />
<ext:Column ColumnID="Descricao" Header="Descrição" Width="300" Sortable="true" DataIndex="Descricao" />
<ext:Column ColumnID="GestaoCredito" Header="Gestão de Crédito" Width="200" Sortable="true"
DataIndex="GestaoCredito" />
<ext:Column ColumnID="OrigemRecurso" Header="Origem do Recurso" Width="250" Sortable="true"
DataIndex="OrigemRecurso" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" SingleSelect="true" ID="rsGrdPesquisaLinhaCredito">
<DirectEvents>
<RowSelect OnEvent="grdPesquisaLinhaCredito_Select">
<EventMask ShowMask="true" Target="CustomTarget" CustomTarget="#{grdPesquisaLinhaCredito}" />
</RowSelect>
</DirectEvents>
</ext:RowSelectionModel>
</SelectionModel>
<LoadMask ShowMask="true" />
<BottomBar>
<ext:PagingToolbar ID="pgnGrdPesquisaLinhaCredito" runat="server" PageSize="10"
StoreID="StorePesquisaLinhaCredito" />
</BottomBar>
</ext:GridPanel>
Store Refresh Event Handler: protected void StorePesquisaLinhaCredito_Refresh(object sender, StoreRefreshDataEventArgs e)
{
StorePesquisaLinhaCredito.DataSource = ObterLinhasCredito(e);
}
protected IList<LinhaCredito> ObterLinhasCredito(StoreRefreshDataEventArgs storeArgs = null)
{
int pageIndex = pgnGrdPesquisaLinhaCredito.PageIndex;
PD.Library.Messages.Paging paginacao;
int DefaultPageSize;
if (storeArgs != null)
paginacao = new Paging()
{
InitialIndex = storeArgs.Start,
OrderByField = storeArgs.Sort == "OrigemRecurso" ? "OrigemRecurso.Codigo" : storeArgs.Sort == "GestaoCredito" ? "GestaoCredito.Codigo" : storeArgs.Sort,
PageSize = storeArgs.Limit,
DirectionOrder = storeArgs.Dir == Ext.Net.SortDirection.DESC ? Paging.Direction.DESC : Paging.Direction.ASC
};
else
paginacao = new Paging()
{
InitialIndex = 0,
PageSize = int.TryParse(PD.Library.Configuration.Manager.GetAppKey("Application.DefaultPageSize"), out DefaultPageSize) ? DefaultPageSize : 10
};
//if (string.IsNullOrEmpty(paginacao.OrderByField))
// paginacao.OrderByField = "Numero";
decimal? numero = null;
string codigoOrigem = null;
string codigoGestaoCredito = null;
if (!string.IsNullOrEmpty(txtFiltroNumero.Text.Trim()))
numero = Convert.ToDecimal(txtFiltroNumero.Value);
if (!string.IsNullOrEmpty(cmbFiltroOrigemRecurso.SelectedItem.Value))
codigoOrigem = cmbFiltroOrigemRecurso.SelectedItem.Value;
if (!string.IsNullOrEmpty(cmbFiltroGestaoCredito.SelectedItem.Value))
codigoGestaoCredito = cmbFiltroGestaoCredito.SelectedItem.Value;
MessageCollection<LinhaCredito> msg = Fachada.Repositorio.LinhaCredito.ObterLinhasCreditoPorFiltro(numero, txtFiltroSigla.Text.Trim().ToUpper(),
txtFiltroDescricao.Text.Trim().ToUpper(), codigoOrigem, codigoGestaoCredito, paginacao);
if (msg.Result != Message.ResultType.Success)
throw msg.Exception;
(this.StorePesquisaLinhaCredito.Proxy[0] as PageProxy).Total = paginacao.ResultCount;
if (paginacao.PageCount == 0) paginacao.PageCount = 1;
if (pageIndex > paginacao.PageCount)
pgnGrdPesquisaLinhaCredito.PageIndex = paginacao.PageCount;
return msg.Instances;
}
Export Button Click Event Handler:protected void ToExcel(object sender, EventArgs e)
{
string json = GridData.Value.ToString();
StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
XmlNode xml = eSubmit.Xml;
this.Response.Clear();
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls");
XslCompiledTransform xtExcel = new XslCompiledTransform();
xtExcel.Load(Server.MapPath("Excel.xsl"));
xtExcel.Transform(xml, null, this.Response.OutputStream);
this.Response.End();
}
It Works, but only for the first page because i am using remote paging and sort.How to solve this problem?
Last edited by Daniil; Oct 13, 2010 at 12:12 PM.
Reason: [CLOSED]