1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    0
    eaglefox12 is on a distinguished road

      0  

    Default GridView From Sql DB

    GridView From Sql DB


    Hello everyone,
    I am trying to make a gridview and I am able to do that successfully using hardcoded data.

    Code:
    var store = Ext.create('Ext.data.Store', {
                storeId: 'myData',
                //url: 'GridViewController',
                fields: [
                    { name: 'Q1', type: 'int' },
                    { name: 'Q2', type: 'int' },
                    { name: 'Q3', type: 'int' },
                    { name: 'Q4', type: 'int' },
                    { name: 'Q5', type: 'int' },
                    { name: 'Improvements', type: 'string' },
                    { name: 'Comments', type: 'string'}],
                data: { 'items': [
                { "Q1": "1", "Q2": "2", "Q3": "4", "Q4": "4", "Q5": "5", "Improvements": "Wut Is Up", "Comments": "Nothing" },
                { "Q1": "1", "Q2": "1", "Q3": "3", "Q4": "4", "Q5": "5", "Improvements": "Wut Is Up1", 
    "Comments": "Nothing13"}]
                },
                proxy: {
                    type: 'memory',
                    //url: 'GridViewController'
                    reader: {
                        type: 'json',
                        root: 'items'
                    }
                }
            });
    
            //store.load();   
            this.grid = Ext.create('Ext.grid.Panel', {
                title: 'GridView App',
                store: Ext.data.StoreManager.lookup('myData'),
                columns: [
                //{ id: 'id', header: 'ID', width: 30,
                //    sortable: true, dataIndex: 'id'
                //},
                {header: 'Q1', width: 100, sortable: true, dataIndex: 'Q1' },
                { header: 'Q2', width: 100, sortable: true, dataIndex: 'Q2' },
                { header: 'Q3', width: 100, sortable: true, dataIndex: 'Q3' },
                { header: 'Q4', width: 100, sortable: true, dataIndex: 'Q4' },
                { header: 'Improvements', width: 200, sortable: true, dataIndex: 'Improvements' },
                { header: 'Comments', width: 200, sortable: true, dataIndex: 'Comments' }
            ],
                stripeRows: true,
                //height:250,
                width: 800,
                renderTo: Ext.getBody()
            });
    This works fine... But now I want to get data from sql db and use URL... like url:GridViewController (like in the code)...
    here's my contoller
    Code:
    public void GridViewController()
            {
    
                Response.Write("Survey Completed!");
                SqlConnection conn = DBTools.GetDBConnection("ApplicationServices2");
                string sqlquery = "Select Q1, Q2, Q3, Q4, Improvements, Comments FROM MyTable";
                SqlCommand cmd = new SqlCommand(sqlquery, conn);
    
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                        //json.Add(reader.GetInt32(0), reader.GetString(1));
                    reader.Close();
                }
    
                //cmd.Connection = conn;
                conn.Open();
                //cmd.ExecuteNonQuery();
                conn.Close();
    
            }
    I am lost as to how to implement this. Please help.

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,912
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    You server simply needs to return json.

    Here few apps that display how to get data from server:
    http://www.sencha.com/forum/showthread.php?229457

    See the response coming back from server

    Scott.

  3. #3
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    0
    eaglefox12 is on a distinguished road

      0  

    Default Thanks

    Thanks


    Thank you Scott, I am just starting extjs, so I really appreciate your help.

    I am looking at your examples. You use php.. I am using c#... how do I get json to get the value from sql db. I don't see where the credentials actually go.

    Thank you again.

    -Jackson

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,912
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    list.php should have the code for extracting data from DB

    Scott.

  5. #5
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    0
    eaglefox12 is on a distinguished road

      0  

    Default


    I am so sorry for being a pain, but I can't figure out the php... is there anyway I can do the same in c#.
    I have my own select statment from above.
    Code:
    $sql = 'SELECT * FROM products';
        
        $result = mysql_query($sql); // result set 
        
        while($rec = mysql_fetch_array($result, MYSQL_ASSOC)){
            $arr[] = $rec;
        };
    
        $rows = 10; // dummy value; used for paging; not needed here
        $data = json_encode($arr);  //encode the data in json format
          
        echo '({"total":"' . $rows . '","data":' . $data . '})';

  6. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,912
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Sorry, I am not that well versed at C#. The idea here is to get the data in an array and the encode it as JSON and send the data back. The last 2 lines is where this happens.

    There should be examples at:
    http://www.ext.net/

    Scott.

  7. #7
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    0
    eaglefox12 is on a distinguished road

      0  

    Default


    That is exactly what I am trying to do but in C#.. but thanks for your time and input Scott

    -Jackson

  8. #8
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

Thread Participants: 2

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi