Get All Data From GridPanel

  1. #1

    Get All Data From GridPanel

    hii

    how i can get all data in gridpanel

    in old version of Ext.Net
    i Use This Code

    (JavaScript)
    
    var function = ViewDate(grid){
    
    var GridViewData = Sys.Serialization.JavaScriptSerializer.serialize(Ext.getCmp(grid.id).getRowsValues());
    
    }
    the correct output like this

    Click image for larger version. 

Name:	2.PNG 
Views:	197 
Size:	71.8 KB 
ID:	24101




    now i use Ext.net 3.2


    but when i use this code Ext.getCmp(grid.id).getRowsValues();

    Bring me something wrong

    like this


    Click image for larger version. 

Name:	1.PNG 
Views:	202 
Size:	31.1 KB 
ID:	24102


    thanks
  2. #2

    Any help plz

    Any help Plzzzzzzzzzzz
  3. #3
    Hi @AbdallahAshour,

    Please provide a test case to reproduce the problem.
  4. #4

    my test case

    hi mr @Daniil


    i have gridpanel contain data
    i need to get all data in the gridpanel

    i need it in JavaScript
    like this


    
    Ext.getCmp(grid.id).getRowsValues()

    i have grid panel like this

    this is my test case
    i have Column (DateColumn) title for that column is (lastChange)

    When is don't contain data and i use the function to get data from grid panel i don't see that column (lastChange)


     Ext.getCmp(grid.id).getRowsValues()
    this my Image

    Click image for larger version. 

Name:	1.PNG 
Views:	180 
Size:	60.0 KB 
ID:	24182

    but When that Column Contain Data he get data

    like this but not for all


    Click image for larger version. 

Name:	2.PNG 
Views:	136 
Size:	75.7 KB 
ID:	24184


    i need now function to get all data in the View (in JavaScript)

    Plz Help me
  5. #5
    Please try SubmitEmptyValue="Null".
    <ext:ModelField Name="lastChange" Type="Date" SubmitEmptyValue="Null" />
    Then if there is no value, it appears a null in a result of getRowsValues call .
  6. #6
    thank you mr.@Daniil

    another question how i can get data from grid panel like in view

    example:

    the data in store:

    Money:1000

    in the View:
    Money:1,000

    i want to get data from grid like view
  7. #7
    Unfortunately, there is no such an option for getRowsValues.

    You can go throught the data returned by a .getRowsValues() call and transform as needed.

    Also you can try with
    Ext.net.GridPrinter.convertData(grid, grid.headerCt.getGridColumns(), {});
    and see if it does the job that you need.
  8. #8
    thank you @Daniil Very much

    yes it work
    and that what i need


    but i see simple problem

    when column name contain (-) like this (Branch-Name)
    it give me tow column (Branch-Name) and (BranchName)

    Click image for larger version. 

Name:	1234.PNG 
Views:	137 
Size:	42.2 KB 
ID:	24191
  9. #9
    Reproduced. I investigated why it happens. It might be required for the printing functionality.

    Okay, I took Ext.net.GridPrinter.convertData as a base and adjusted it to the requirement.

    Example
    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test11", "test21" },
                    new object[] { "test12", "test22" },
                    new object[] { "test13", "test23" }
                };
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v3 Example</title>
    
        <script>
            var getGridPanelData = function (grid, config) {
                var data = [],
                    columns = grid.headerCt.getGridColumns(),
                    config = config || {};
    
                Ext.each(config.currentPageOnly ? grid.store.getRange() : grid.store.getAllRange(), function (record, index) {
                    var item = {},
                        i, len, c, meta, value;
    
                    for (i = 0, len = columns.length; i < len; i++) {
                        c = columns[i];
    
                        if (c.dataIndex) {
                            value = record.data[c.dataIndex];
                            meta = { tdCls: "", tdAttr: "", style: "" };
                            value = c.renderer ? c.renderer.call(c, value, meta, record, index, i, grid.store, grid.view) : value;
                            item[c.dataIndex] = value;
                        } else if (c.isXType("rownumberer")) {
                            meta = { tdCls: "", tdAttr: "", style: "" };
                            item[Ext.String.createVarName(c.id)] = c.renderer.call(c, null, meta, record, index, i, grid.store, grid.view); //index + 1;
                        } else if (column.isXType("templatecolumn")) {
                            value = c.tpl ? c.tpl.apply(record.data) : value;
                            item[Ext.String.createVarName(c.id)] = value;
                        }
                    }
    
                    item.__internalId = record.internalId;
                    data.push(item);
                });
    
                return data;
            };
    
            var onButtonClick = function() {
                console.log(getGridPanelData(App.GridPanel1));
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Get data" Handler="onButtonClick" />
    
            <ext:GridPanel ID="GridPanel1" runat="server">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="test1" />
                                    <ext:ModelField Name="test-2" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column runat="server" Text="Test 1" DataIndex="test1" />
                        <ext:Column runat="server" Text="Test 2" DataIndex="test-2" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
  10. #10
    thank you @Daniil Very much

    It works as I want

Similar Threads

  1. Replies: 1
    Last Post: Oct 27, 2014, 8:46 AM
  2. Replies: 2
    Last Post: Sep 17, 2013, 11:57 PM
  3. Replies: 2
    Last Post: Aug 22, 2012, 4:03 PM
  4. Replies: 0
    Last Post: Jun 19, 2009, 4:18 AM
  5. Replies: 4
    Last Post: Nov 17, 2008, 8:16 AM

Tags for this Thread

Posting Permissions