How to control your Exporting Data in Ext.Net

  1. #1

    How to control your Exporting Data in Ext.Net

    Hello!
    My question is How I can export data from Gridview or data source after filtering and ordering data in side the gridview
    for example if I sort my gridview data decinding and I hide some column also filter by date! I want to export to xsl and have the same output, same look as my gridview look.
    this is availabile in windows application and I don't know if it's possible to do that in web? see the picture for more information

    Click image for larger version. 

Name:	pic.jpg 
Views:	51 
Size:	91.5 KB 
ID:	6339


    / Thanks Medo
  2. #2
    it seems the way export work it is just export what you load from database in form loading!!!
    needs explanation!!!
    why is this code executed on load???
    <script type="text/javascript">
            var submitValue = function (g, hiddenFormat, format) {
                hiddenFormat.setValue(format);
                g.submitData(false, { isUpload: true });
              
            };
            var template = '<span style="color:{0};">{1}</span>';
            var change = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value);
            };
            var pctChange = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value + "%");
            };
        </script>
    Last edited by Daniil; Jun 25, 2013 at 6:59 AM. Reason: Please use [CODE] tags
  3. #3
    Hello Medo.

    Here is a small example about one of the ways you can do that:
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.Store1.DataSource = new object[]
                {
                    new object[] { 1, "3m Co", 71.72, 0.02, "8/1 12:00am", 0.03 },
                    new object[] { 2, "Alcoa Inc", 29.01, 0.42, "7/1 12:00pm", 1.47 },
                    new object[] { 3, "Walmart", 1.72, 0.42, "9/1 12:00am", 0.33 },
                };
    
                this.Store1.DataBind();
            }
        }
    
        protected void Testing(object sender, DirectEventArgs e)
        {
            X.MessageBox.Alert("Test", GridData.Value.ToString()).Show();
        }
    
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Export Data from GridPanel into Excel using a full PostBack - Ext.NET Examples</title>
        <link href="resources/css/examples.css" rel="stylesheet" type="text/css" />
    
        <script type="text/javascript">
            var saveData = function() {
                GridData.setValue(Ext.encode(GridPanel1.getRowsValues({ selectedOnly: false })));
            };
        </script>
    
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Hidden ID="GridData" runat="server" />
        <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:ArrayReader>
                    <Fields>
                        <ext:RecordField Name="id" Type="Int" />
                        <ext:RecordField Name="company" />
                        <ext:RecordField Name="price" Type="Float" />
                        <ext:RecordField Name="change" Type="Float" />
                        <ext:RecordField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
                        <ext:RecordField Name="pctChange" Type="Float" />
                    </Fields>
                </ext:ArrayReader>
            </Reader>
            <DirectEventConfig IsUpload="true" />
        </ext:Store>
        <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" StripeRows="true"
            TrackMouseOver="true" Width="600" Height="350" AutoExpandColumn="Company">
            <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column ColumnID="Company" Header="Company" Width="160" DataIndex="company" />
                    <ext:Column Header="Price" Width="75" DataIndex="price">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                    <ext:Column Header="Change" Width="75" DataIndex="change" />
                    <ext:DateColumn Header="Last Updated" Width="85" DataIndex="lastChange" Format="dd/MM/yyyy" />
                    <ext:Column Header="Pct.Change" Width="75" DataIndex="pctChange" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
            </SelectionModel>
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                        <ext:Button ID="Button2" runat="server" Text="Show Data" Icon="Accept">
                            <Listeners>
                                <Click Fn="saveData" />
                            </Listeners>
                            <DirectEvents>
                                <Click OnEvent="Testing" />
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
        </ext:GridPanel>
        </form>
    </body>
    </html>
    This is the command that save the data from the GridPanel into a HiddenField:
    GridData.setValue(Ext.encode(GridPanel1.getRowsValues({ selectedOnly: false })));
    There you can configure what you want to save from the grid.
    In this post http://forums.ext.net/showthread.php...ll=1#post48451 you can see a better explanation about those configurations.

    Hope this helps.
  4. #4
    Hello! Thanks for your replay!
    I just have question I got this error when I tried your code! "'Ext.Net.ArrayReader' does not have a public property named 'Fields'"

    Click image for larger version. 

Name:	errorrr.PNG 
Views:	12 
Size:	12.9 KB 
ID:	6817


    regarding your code bellow!!

    Quote Originally Posted by DanielU View Post
    Hello Medo.
        <ext:Store ID="Store1" runat="server">
            <Reader>
                <ext:ArrayReader>
                    <Fields>
                        <ext:RecordField Name="id" Type="Int" />
                        <ext:RecordField Name="company" />
                        <ext:RecordField Name="price" Type="Float" />
                        <ext:RecordField Name="change" Type="Float" />
                        <ext:RecordField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
                        <ext:RecordField Name="pctChange" Type="Float" />
                    </Fields>
                </ext:ArrayReader>
            </Reader>
            <DirectEventConfig IsUpload="true" />
        </ext:Store>
    Tanks A lot!
    Medo
  5. #5
    I copied this example and tried again. It worked fine.
    Could it be the version?
    Mine is 1.5.0.0
  6. #6
    Quote Originally Posted by DanielU View Post
    I copied this example and tried again. It worked fine.
    Could it be the version?
    Mine is 1.5.0.0
    Hello
    I used version 2.2.0 in this case which controls I should use instead of have DirectEventConfig, and Array Reader?
    or what other option I can do?

    thanks
  7. #7
    Last edited by DanielU; Aug 28, 2013 at 2:02 PM.

Similar Threads

  1. Exporting data from Gridpanel to file
    By tanky65 in forum 2.x Help
    Replies: 0
    Last Post: May 22, 2012, 10:08 AM
  2. Columns Names are not displaying while exporting data
    By SATEESHKUMAR in forum 1.x Help
    Replies: 0
    Last Post: Mar 30, 2011, 4:33 AM
  3. negative id values while exporting data
    By emon in forum 1.x Help
    Replies: 0
    Last Post: Mar 05, 2011, 6:12 AM
  4. Exporting data from the grid
    By emon in forum 1.x Help
    Replies: 0
    Last Post: Mar 05, 2011, 3:40 AM
  5. [CLOSED] Exporting Data using Refresh event
    By ecerrillos in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 22, 2010, 3:32 PM

Tags for this Thread

Posting Permissions