1. #1
    Ext User
    Join Date
    Apr 2008
    Posts
    64
    Vote Rating
    0
    tzander is on a distinguished road

      0  

    Default DataView Template with button

    DataView Template with button


    Hi I Have a Template for a DataView :

    HTML Code:
    	var tpl = new Ext.XTemplate(
    		    '<tpl for=".">',
    			'<div id="{id}" class="thumb-wrap" >',
    		    '<p><br>[B]<input type="button" id="delete-button" value="delete" />[/B]',
    			'<input type="radio" name="is_startbild" value="{id}" {is_startbild}></p>',
    		    '<div class="thumb"><img src="../services.php?{url}" title="{name}" width=80></div>',
    		    '</div>',
    		    '</tpl>',
    			);
    Now ic want to fetch the button in oder to catch an event with Ext.get('delete-button') but it always says Ext.get('delete-button') is null


    Thanks for help

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    As usual. Add a click handler to the DataView. Test the target of the event in the listener to see if it took place in a button.

    Of course, you know DOM IDs must be unique? Don't you?

  3. #3
    Ext User
    Join Date
    Apr 2008
    Posts
    64
    Vote Rating
    0
    tzander is on a distinguished road

      0  

    Default


    yes I know with the unique Id:

    here is my code nothing happens:

    Code:
    BilderTemplate = Ext.extend(Ext.DataView, {
    	
     	initComponent: function(){
    		var store = new Ext.data.JsonStore({
    			url: '../services.php?class=EventService&method=getFiles',
    			fields: ['id', 'url', 'name', 'is_startbild'],
    			root: 'data'
    		});
    
    		var tpl = new Ext.XTemplate(
    		    '<tpl for=".">',
    			'<div id="{id}" class="thumb-wrap" >',
    		    '<p><br><input type="button" id="delete-bild-button" value="l&ouml;chen" />',
    			'<input type="radio" name="is_startbild" value="{id}" {is_startbild}></p>',
    		    '<div class="thumb"><img src="../services.php?{url}" title="{name}" width=80></div>',
    		    '</div>',
    		    '</tpl>',
    		 
    		);
    		
    	
    		Ext.apply(this, {
    			store: store,
    		        tpl: tpl,
    		        multiSelect: false,
    		        singleSelect: true,
    		        overClass:'x-view-over',
    		        itemSelector:'div.thumb-wrap',
    		        emptyText: 'Keine Bilder vorhanden',
    				handler: function(a, b, c){
    					debugger;
    				},
    				listeners: function(a, b, c){
    							debugger;
    				}
    		   
    		});
    	  BilderTemplate.superclass.initComponent.apply(this,arguments);
        } // eo function initComponent
    });

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Looks like you don't. For each item you have

    Code:
    id="delete-bild-button"
    DO NOT extend to configure.

    It's a copy+pasted way of avoiding writing code. You hoiked it once out of somewhere you got code from, and then never thought about the issue again.

    listeners CAN NOT be added in initComponent.

    And anyway, have you ever added listeners using that object format? Ever?

    Code:
    listeners: function(){...}
    What events? YOU have added listeners before, so yuo DO know how to do it. You're just flapping.

  5. #5
    Sencha User hcervantes's Avatar
    Join Date
    Mar 2007
    Location
    Centerville, OH
    Posts
    80
    Vote Rating
    0
    hcervantes is on a distinguished road

      0  

    Default How to "Test the target "

    How to "Test the target "


    Hi Animal. I'm working with an dataview and I also want to add a delete button. I've done as you suggested, yet I don't know how to "Test the target" to see if the button fired the event. The onPictureViewSelect function dataViewModel, record, and options as parameters. How do I test for the button click?

    Can you point me in the right direction, please?
    Many thanks in advance.

    Here is my code:
    Code:
    {
                                                                xtype: 'dataview',
                                                                border: 1,
                                                                frame: true,
                                                                itemId: 'pictureView',
                                                                autoScroll: true,
                                                                emptyText: 'No Images',
                                                                itemSelector: 'div.thumb-wrap',
                                                                itemTpl: [
                                                                    '<div id="{ID}" class="thumb-wrap" >',
                                                                    '    <p><br><input type="button" id="delete-button{ID}" value="delete" />	',
                                                                    '	<div class="thumb"><img src="images/{PICTURE}" title="{PICTURE}" width=200></div>',
                                                                    '</div>'
                                                                ],
                                                                overItemCls: 'x-item-over',
                                                                store: 'pictureStore',
                                                                trackOver: true,
                                                                listeners: {
                                                                    select: {
                                                                        fn: me.onPictureViewSelect,
                                                                        scope: me
                                                                    }
                                                                }
                                                            }
    onPictureViewSelect:
    Code:
     onPictureViewSelect: function(dataviewmodel, record, eOpts) {
            Ext.Msg.alert('Status', 'Changes saved successfully.');
        },
    -Hector Cervantes
    GIS Pro

Thread Participants: 2