[CLOSED] Passing JSON to Reader

  1. #1

    [CLOSED] Passing JSON to Reader

    Is it possible for me to pass some JSON data that I have sourced myself to a store, which can then be used in a grid?

    It looks like I can use the JSON Reader to read it in, but how do I actually pass the JSON to the reader?

    Thanks,
    Ben

    Same JSON:

    var someJsonData = {"d":{"Total":2,"Target":null,"Rows":[{"Description":"Foo","Quantity":62.00,"Id":"b02a0982-3c8f-4a1e-aa57-076074939b54"},{"Description":"Bar","Quantity":130.00,"Id":"b81f6769-7794-4196-a616-4a139011bc16"}]}};

  2. #2

    RE: [CLOSED] Passing JSON to Reader

    Hi Ben,

    At now there is no ability to set JSON directly. But you can make own Store control (which will be inherited from Coolite Store) and open public access for protected property JsonData. The uses this property if Data property is null

    public class MyStore : Store
        {
            public string MyJsonData
            {
                get { return this.JsonData; }
                set { this.JsonData = value; }
            }
        }
    I did not test it but it should works


  3. #3

    RE: [CLOSED] Passing JSON to Reader

    Thank you for the reply. So it's not possible to pass the JSON to the store on the client?

    Ben
  4. #4

    RE: [CLOSED] Passing JSON to Reader

    Hi,

    The single way to pass JSON to the client is using HttpProxy with HttpHandler/WebService.
    We will think about more ways which allows to pass clear JSON and handle it


  5. #5

    RE: [CLOSED] Passing JSON to Reader

    Thanks Vladimi.

    Ben
  6. #6

    RE: [CLOSED] Passing JSON to Reader

    Hi Ben,

    The Store has loadData method. You can pas your object to this method

    Here is example
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
         {
             this.Store1.DataSource = new List<Company> 
             { 
                 new Company("3m Co", 71.72, 0.02, 0.03),
                 new Company("Alcoa Inc", 29.01, 0.42, 1.47),
                 new Company("Altria Group Inc", 83.81, 0.28, 0.34),
                 new Company("American Express Company", 52.55, 0.01, 0.02),
                 new Company("American International Group, Inc.", 64.13, 0.31, 0.49),
                 new Company("AT&amp;T Inc.", 31.61, -0.48, -1.54),
                 new Company("Boeing Co.", 75.43, 0.53, 0.71),
                 new Company("Caterpillar Inc.", 67.27, 0.92, 1.39),
                 new Company("Citigroup, Inc.", 49.37, 0.02, 0.04),
                 new Company("E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28),
                 new Company("Exxon Mobil Corp", 68.1, -0.43, -0.64),
                 new Company("General Electric Company", 34.14, -0.08, -0.23),
                 new Company("General Motors Corporation", 30.27, 1.09, 3.74),
                 new Company("Hewlett-Packard Co.", 36.53, -0.03, -0.08),
                 new Company("Honeywell Intl Inc", 38.77, 0.05, 0.13),
                 new Company("Intel Corporation", 19.88, 0.31, 1.58),
                 new Company("International Business Machines", 81.41, 0.44, 0.54),
                 new Company("Johnson &amp; Johnson", 64.72, 0.06, 0.09),
                 new Company("JP Morgan &amp; Chase &amp; Co", 45.73, 0.07, 0.15),
                 new Company("McDonald\"s Corporation", 36.76, 0.86, 2.40),
                 new Company("Merck &amp; Co., Inc.", 40.96, 0.41, 1.01),
                 new Company("Microsoft Corporation", 25.84, 0.14, 0.54),
                 new Company("Pfizer Inc", 27.96, 0.4, 1.45),
                 new Company("The Coca-Cola Company", 45.07, 0.26, 0.58),
                 new Company("The Home Depot, Inc.", 34.64, 0.35, 1.02),
                 new Company("The Procter &amp; Gamble Company", 61.91, 0.01, 0.02),
                 new Company("United Technologies Corporation", 63.26, 0.55, 0.88),
                 new Company("Verizon Communications", 35.57, 0.39, 1.11),
                 new Company("Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63)
             };
    
             this.Store1.DataBind(); 
        }
    
        public class Company
        {
            public Company(string name, double price, double change, double pctChange)
            {
                this.Name = name;
                this.Price = price;
                this.Change = change;
                this.PctChange = pctChange;
            }
    
            public string Name { get;set; }
            public double Price { get;set; }
            public double Change { get;set; }
            public double PctChange { get;set; }
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        
        <script type="text/javascript">
            function load_data() {
                var data = [
                    { "Name": "1", "Price": 1, "Change": 0, "PctChange": 0 },
                    { "Name": "2", "Price": 1, "Change": 0, "PctChange": 0 }
                ];
    
                Store1.loadData(data);
            }
    
        </script>
    
    </head>
    <body>
        <ext:ScriptManager ID="ScriptManager1" runat="server" StateProvider="None" />
    
        <ext:Store ID="Store1" runat="server" >
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="Name" />
                        <ext:RecordField Name="Price" />
                        <ext:RecordField Name="Change" />
                        <ext:RecordField Name="PctChange" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        
        <ext:GridPanel 
            ID="GridPanel1" 
            runat="server" 
            StoreID="Store1"
            StripeRows="true"
            Title="Company List"
            AutoExpandColumn="Company"
            Width="600"
            Height="350">
            <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column ColumnID="Company" Header="Company" Width="160" Sortable="true" DataIndex="Name" />
                    <ext:Column Header="Price" Width="75" Sortable="true" DataIndex="Price"/>
                    <ext:Column Header="Change" Width="75" Sortable="true" DataIndex="Change"/>
                    <ext:Column Header="Change" Width="75" Sortable="true" DataIndex="PctChange"/>
                </Columns>
            </ColumnModel>        
        </ext:GridPanel>
        
        <ext:Button runat="server" Text="New Data">
            <Listeners>
                <Click Fn="load_data" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Hope this help


Similar Threads

  1. Replies: 4
    Last Post: Mar 20, 2012, 1:27 PM
  2. [CLOSED] Store: Passing JSON data directly to Server-Side
    By nhg_itd in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 09, 2012, 2:08 AM
  3. [CLOSED] Reader id issue in Store
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 20, 2011, 12:04 PM
  4. [CLOSED] Advanced XML / JSON Reader
    By Immobilmente in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 09, 2010, 5:53 AM
  5. Json reader not retrive all pages of data in grid panel
    By Satyanarayana murthy in forum 1.x Help
    Replies: 0
    Last Post: Dec 05, 2009, 4:58 AM

Posting Permissions