-
5 Feb 2009 6:35 AM #1
handler to button in Ext.XTemplate
handler to button in Ext.XTemplate
Hello,
is this possible anyway?
I have a JsonStore loading data.
In a Panel I show the store with a DataView which uses XTemplate to render the data
In the XTemplate I would like to include a button to click on.
But how can I register a handler to the button in the XTemplate?
-
5 Feb 2009 8:05 AM #2
Posting your code might be appropriate.
MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow
-
5 Feb 2009 9:22 AM #3
This is my template:
This is the code for the panel where the DataView is loaded with the data of store (JsonStore)Code:var tpl = new Ext.XTemplate( '<tpl for=".">', '<div class="thumb-wrap" id="{name}">', '<img src="{url}" title="{name}">', '<span>Name: {name} {vorname}, {alter} Jahre', '<input type="button" name="addButton" value="Add" id="addButton" /></div>', '</tpl>' );
I know want to be able to react on a click event on the "Add" button.Code:var panel = new Ext.Panel({ id:'images-view', frame: true, width:535, autoHeight:true, collapsible:true, layout:'fit', title:'', items: new Ext.DataView({ id: 'myView', store: store, tpl: tpl, autoHeight:true, multiSelect: true, overClass:'x-view-over', itemSelector:'div.thumb-wrap', emptyText: 'No images to display' }) }); panel.render('myPanel');
How can I do this?
-
5 Feb 2009 9:41 AM #4
Use the DataView's click event, and just check the target is a button.
BTW, ids must be unique. You will end up with several "addButton" buttons.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
5 Feb 2009 10:06 AM #5
Puh, could you maybe give a little piece of code for a beginner

-
5 Feb 2009 10:26 AM #6
HTML Code:/* * Ext JS Library 2.2 * Copyright(c) 2006-2008, Ext JS, LLC. * licensing@extjs.com * * http://extjs.com/license */ Ext.onReady(function(){ var data = [["xx", "aa", "fff", "cco"]]; var tpl = new Ext.XTemplate( '<tpl for=".">', '<div class="thumb-wrap" id="{name}">', '<img src="{url}" title="{name}">', '<span>Name: {name} {vorname}, {alter} Jahre', '<input type="button" name="addButton" value="Add"/></div>', '</tpl>' ); var store = new Ext.data.SimpleStore({ fields: [ {name: 'name'}, {name: 'url'}, {name: 'vorname'}, {name: 'alter'} ], data: data }); var panel = new Ext.Panel({ frame: true, width:535, autoHeight:true, collapsible:true, layout:'fit', title:'', items: new Ext.DataView({ store: store, tpl: tpl, autoHeight:true, multiSelect: true, overClass:'x-view-over', itemSelector:'div.thumb-wrap', emptyText: 'No images to display', listeners:{ click: function(dataView, index, node, e ){ var target = e.getTarget(); if(target.name == "addButton"){ alert("doStuff"); } } } }) }); panel.render('xx'); });
-
5 Feb 2009 10:46 AM #7
Wow!
Thanks a lot!!!
Now I understand!
Really, really, thanks a lot!!!
-
5 Feb 2009 11:12 AM #8
-
5 Feb 2009 11:16 AM #9
Thanks!
I already got the next problem...
With special chars, the german äüöß...
Database is in UTF-8, webpage has utf-8 and even the php site now sends a header with utf-8 (I can see in Firefox) but the json data I have from the database is stripped.
This is what I get:
instead of:Code:({"total":"1","results":[{"0":"0","id":"0","1":"M","name":"M","2":"Max","vorname":"Max","3":"55","alter" :"55"}], "umlaute": "äüöß"})
I hardcoded the "umlaute": "äüöß" this works....Code:({"total":"1","results":[{"0":"0","id":"0","1":"M","name":"Müller","2":"Max","vorname":"Max","3":"55","alter" :"55"}], "umlaute": "äüöß"})
-
5 Feb 2009 11:42 AM #10MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow


Reply With Quote