1
votes

I am new to Sencha Touch2 and facing problem while passing data from my Controller to Floating panel on listitem tap. Here is my controller implementation code:

Ext.define('CustomList.controller.Main', {
    extend: 'Ext.app.Controller',
    requires:['CustomList.view.DatePanel'],

    config: {
        refs: {
            listView: 'listitems'
        },

        control: {
            'main test2 list': {
                activate: 'onActivate',
                itemtap: 'onItemTap'
            }
        }
    },

    onActivate: function() {
        console.log('Main container is active');
    },

    onItemTap: function(view, index, target, record, event) {
        console.log('Item was tapped on the Data View');
        Ext.Viewport.add({
            xtype: 'DatePanel'
        });
     }

});

Am able to get data in the controller and DatePanel.js is my floating Panel. DatePanel.js:

Ext.define('CustomList.view.DatePanel', {
    extend: 'Ext.Panel',
    alias: 'widget.DatePanel',
    xtype:'datepanel',
    config: {
        itemid:'DatePanel',
        modal:true,
        centered: true,
        hideOnMaskTap:true,
        width:'500px',
        height:'650px',
        items:[
            {
                styleHtmlCls:'homepage',
                tpl:'<h4>{name3}</h4>'

            },
            {
                xtype:'toolbar',
                docked:'bottom',
                items:[{
                    text:'OK',
                    ui:'confirm',
                    action:'ShowTurnOverReport',
                    listeners : {
                        tap : function() {
                            console.log('Ok');
                        }
                    }
                },
                    {
                        text:'Cancel',
                        ui:'confirm',
                        action:'Cancel',
                        listeners : {
                            tap : function() {
                            console.log('Cancel');
                            var panelToDestroy = Ext.getCmp('datepanel');
                            panelToDestroy.destroy();
                            Ext.Viewport.add(Ext.create('CustomList.view.Test2'));//Test.js is my list Panel

                            }
                        }
                    }]

            }
        ]
    }
});

Help me out in destroying the panel on 'Cancel' Button. Can anyone please help me. Thanks.

1
use id value 'DatePanel' in getCmp. - SachinGutte

1 Answers

2
votes

Create instance of panel you want to add first.

var floatingDatePanel = Ext.create('Yourapp.view.YourDatePanel');

Next get data of selected list item on itemTap

var data = record.getData();

Assign this data to floatingDatePanel with setData() method

UPDATE,

after looking at your panel code, I guess you want to set data to first item in panel ie

        {
            styleHtmlCls:'homepage',
            tpl:'<h4>{name3}</h4>'

        }

Right ? If so then you need to change following code

floatingDatePanel.setData(data);

to

floatingDatePanel.getAt(0).setData(data);

Because, it is first item inside panel that is having a template assigned and hopefully the same where you want to set data.

then finally, you can add this panel into viewport with

Ext.Viewport.add(floatingDatePanel);