Let’s say you want to make a simple modal window that appears when you double click on a row in a Sencha Grid Panel.  Let’s assume you have the panel created and in the double click event you need to put some code.  You want that code to pass in some values to the window, then have the window pop up and look something like this:

 

image

 

We know we need to create a form panel, but first, let’s code the double click event in the grid that brings it up.  To do this, we add the DoubleClick event to the Grid Panel and then, using the “record” passed in, we pass that to our new Windows we are about to create.  below is some code I wrote to do this (3 lines).

 

image

 

Next, let’s go into designer and make a simple form that is basically a top level window that has a form panel as a client, then the form panel has a fieldset, and that fieldset has 3 textfields.  Very straight forward and what you end up getting from SA (Sencha Architect) looks like the following.  I won’t go through the drag and drops to make it, but it is pretty straight forward.  It took me about 30 seconds.

 

image

 

The code it created looks like the following (which also contains the load event I entered myself and is pictured separately below it.

Ext.define('MyApp.view.AddressUpdateWindow', {
    extend: 'Ext.window.Window',

    height: 250,
    width: 400,
    title: 'Address Book Update',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'form',
                    bodyPadding: 10,
                    items: [
                        {
                            xtype: 'fieldset',
                            title: 'My Fields',
                            items: [
                                {
                                    xtype: 'textfield',
                                    name: 'City',
                                    fieldLabel: 'City',
                                    anchor: '100%'
                                },
                                {
                                    xtype: 'textfield',
                                    name: 'State',
                                    fieldLabel: 'State',
                                    anchor: '100%'
                                },
                                {
                                    xtype: 'textfield',
                                    name: 'Zip',
                                    fieldLabel: 'Zip',
                                    anchor: '100%'
                                }
                            ]
                        }
                    ],
                    listeners: {
                        afterrender: {
                            fn: me.onFormAfterRender,
                            scope: me
                        }
                    }
                }
            ],
            dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'bottom',
                    items: [
                        {
                            xtype: 'button',
                            handler: function(button, event) {
                                debugger;
                            },
                            text: 'Save'
                        }
                    ]
                }
            ]
        });

        me.callParent(arguments);
    },

    onFormAfterRender: function(abstractcomponent, options) {

        var recordData =
        abstractcomponent.up().recordData;

        abstractcomponent.getForm().setValues(
        recordData
        );

        //abstractcomponent.getForm().setValues({
        //    City: recordData.City,
        //    State: recordData.State,
        //    Zip: recordData.Zip
        //});

    }

});

Below is the code I wrote which you can see incorporated in the code above.  Notice the lines I commented out.  I just did this to show what is really happening, but I condensed it a little in my real JavaScript.

 

image

 

So basically, that’s it.  We created a double click event in a grid panel and from that we opened a pop up form and populated it with data.  Very straight forward.

HTH’s.

Part 1 (this) Basics (mostly server side)
Part 2 ExtJS Client Side Details

 

Introduction

In this series of articles, we will take the reference application build by the Sencha product team for using Sencha’s MVC pattern running with an ASP.NET 4.0 project (IIS in production).  The first article takes the reference Sencha MVC app and with almost no changes, makes it work with the ASP.NET Visual Studio 2010 project.  By default, the application works with JSON static files.  We change that to work with an ASP.NET MVC3 project.  The second article in the series embellishes the application to include a more real user experience by adding additional functionality and data.  The improved functionality includes both date and number columns as well as paging.  It also adds functionality for inserts and deletes which are left out of the base app from Sencha.

Visual Studio Project SenchaMVCASPNetSolution

 

The Final Project when running:

 

image

 

(more…)


© 2012 PeterKellner.net. All Rights Reserved
Follow

Get every new post delivered to your Inbox

Join other followers: