38
ش وز م هازم آ چ ه س ل جEXTJS ش خ ب ن ها چ ن سی ح ا ن ی س دآز زمان آ ان ون پ ه ی ز س د ن ه م. ت ک ر شhttp://armandar.com http://armandar.com

Extjs 4

Embed Size (px)

Citation preview

Page 1: Extjs 4

http://armandar.com

EXTJSجلسه چهارم آموزش حسین جهانبخش

شرکت مهندسی رهپویان آرماندار سیناhttp://armandar.com

Page 2: Extjs 4

http://armandar.com

EXT JSکالس های

Ext Ext.Base Ext.Class Ext.ClassManager Ext.Loader

Page 3: Extjs 4

http://armandar.com

Ext

application define Create onReady Widget getClass getClassName

Page 4: Extjs 4

http://armandar.com

Ext.application

Ext.application({ name: 'MyApp', extend:'MyApp.Application', launch: function() { } })

Page 5: Extjs 4

http://armandar.com

Ext.define

Ext.define(name,data, callback)

Ext.define('Car', { name: null, constructor: function(name) { if (name) { this.name = name; } }, start: function() { alert('Car started'); } });

Page 6: Extjs 4

http://armandar.com

Ext.define extending, overriding and sibleton

Ext.define('ElectricCar', { extend: 'Car', start: function() { alert("Electric car started"); } });

Ext.define('My.ux.field.Text', { override: 'Ext.form.field.Text', setValue: function(val) { this.callParent(['In override']); return this; } });

Ext.define('Logger', { singleton: true, log: function(msg) { console.log(msg); } });

Page 7: Extjs 4

http://armandar.com

Ext.create

Ext.create(Class,Options);

var myCar = Ext.create('ElectricCar',{ name: 'MyElectricCar‘ });

var myCar = new ElectricCar('MyElectricCar');

Ext.Loader

Page 8: Extjs 4

http://armandar.com

Ext.onReady

Ext.onReady(function(){ new Ext.Component({ renderTo: document.body, html: 'DOM ready!‘ }); })

Page 9: Extjs 4

http://armandar.com

Ext.widget

alias: ‘widget.highchart’

یا

xtype: ‘highchart’

Ext.create('Ext.panel.Panel', { renderTo: Ext.getBody(), title: 'Panel‘ }); Ext.widget('panel', { renderTo: Ext.getBody(), title: 'Panel‘ }); Ext.create('widget.panel', { renderTo: Ext.getBody(), title: 'Panel‘ });

Ext.application({ name : 'Fiddle', launch : function() { Ext.create('widget.panel', { renderTo: Ext.getBody(), title: 'Panel‘ }); } })

Page 10: Extjs 4

http://armandar.com

Ext.getClass

var button = new Ext.Button(); Ext.getClass(button); // returns Ext.Button

Page 11: Extjs 4

http://armandar.com

Ext.getClassName

Ext.getClassName(Ext.Button); //returns "Ext.Button"

Page 12: Extjs 4

http://armandar.com

Ext.Base

از آن ارث بری می کند. تمام متدها Ext که تمام کالس های موجود در Ext Jsکالس پایه ای خصوصیات و فیلدهای این کالس در تماس کالس ها دیگر در دسترس است.

Page 13: Extjs 4

http://armandar.com

Ext.Class

برای ایجاد یک کالس استفاده می شود. Ext.ClassManagerکالس پایه ای است کrه توسط استفاده کنید.Ext.defineبنابراین به طور مستقیم از آن استفاده نکنید و به جای آن از

Page 14: Extjs 4

http://armandar.com

Ext.ClassManage

Ext.define Ext.create Ext.widget Ext.getClass Ext.getClassNam

Page 15: Extjs 4

http://armandar.com

Ext.Loader

Ext.require(['widget.window', 'layout.border', 'Ext.data.Connection']);

Ext.require(['widget.*', 'layout.*', 'Ext.data.*');

Ext.exclude('Ext.data.*').require('*');

Armandar.view.About \armandar\view\about.js

Page 16: Extjs 4

http://armandar.com

Events

Ext.create('Ext.Button', { renderTo: Ext.getBody(), listeners: { click: function() { Ext.Msg.alert('Button clicked!'); } } });

Ext.create('Ext.Button', { renderTo: Ext.getBody(), listeners: { mouseout: function() { //Do something }, click: function() { // Do something } } });

var button = Ext.create('Ext.Button');button.on('click', function() { //Do something });

button.on({ mouseover: function() { //Do something }, mouseover: function() { //Do something } })

Page 17: Extjs 4

http://armandar.com

Events

var HandleClick= function() { Ext.Msg.alert('My button clicked!'); }Ext.create('Ext.Button', { listeners: { click: HandleClick } });button.un('click', HandleClick)

Page 18: Extjs 4

http://armandar.com

Events

<div id="mydiv"></div>

var div = Ext.get('mydiv'); div.on('click', function(e, t, eOpts) { // Do something });

Page 19: Extjs 4

http://armandar.com

دسترسی به عناصر صفحه

get query select

Page 20: Extjs 4

http://armandar.com

Ext.get

var mydiv = Ext.get('myDivId'); //returns a Ext.dom.Element

Page 21: Extjs 4

http://armandar.com

Ext.query

var someNodes = Ext.query('.oddRow', myCustomComponent.getEl().dom);

نام بrا کامپوننrت یrک کنیrد برای myCustomComponentفرص دارید، صrفحه در عنصrر بrه دستور domدسrترسی از آrن myCustomComponent.getEl().dom

ارسrال می کنیrم و این queryاسrتفاده می کنیم. آن را گرفتrه بrه عنوان ریشrه بrه دسrتور دارند را به ما برخواهند گرداند.oddRowدستور تمام فرزندهای این عنصر که کrالس

Page 22: Extjs 4

http://armandar.com

Ext.select

var rows = Ext.select('div.row'); //Matches all divs with class row (a CompositeElement )rows.setWidth(100); // All elements become 100 widthExt.select('div.row').setWidth(100);

Ext.select('div.row, span.title'); //Matches all divs with class row and all spans with class title

Ext.get('myEl').select('div.row'); //myEl is root of searchیاExt.select('div.row', true, 'myEl');// This is equivalent to the previous line

Ext.select('div.row[title=bar]:first‘)

Page 23: Extjs 4

http://armandar.com

Ext.ComponentQuery

Ext.ComponentQuery.query('button'); // returns all the components with the xtype button

Ext.ComponentQuery.query('#foo'); //returns a component with the ID of foo

Ext.ComponentQuery.query("button[title='my button']");;یا//parent.query('textfield[title=my button]');

Ext.ComponentQuery.query('formpanel numberfield'); // Gets only the numberfields under a for

parent.child('button[itemId=save]');• nextNode• up• down• previousSibli

ng

Page 24: Extjs 4

http://armandar.com

Component

همrه چیزهایrی کrه شمrا بر روی صrفحه قرار می دهیrد از دکمrه و لیبrل تrا عناصrر پیچیده تر و درخrت همگrی گریrد یrک Componentمثrل کامپوننrت هrر کrه xtype هسrتند. دارد

اسrفاده کنیrد و در زمان اجرا بخواهید Ext,define یrا Ext.createزمانrی کrه نخواهیrد از استفاده نمایید.xtypeیک کامپوننت را ایجاد کنید می توانید از

Page 25: Extjs 4

http://armandar.com

Containers

Ext.toolbar.Toolbar Ext.panel.Panel Ext.container.Container Ext.Editor

Ext.button.Button

Page 26: Extjs 4

http://armandar.com

Containers

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, items: [{ xtype: 'panel', title: 'Panel 1', }, { xtype: 'panel', title: 'Panel 2', height: 200, items: [{ xtype: 'button', text: 'Click Me‘ }] }, { xtype: 'panel', title: 'Panel 3', width: 150, height: 100, }] });

نرم افزار Extjsهر از مجموعه ای هم در کامپوننتهای

تنیده است.

Page 27: Extjs 4

http://armandar.com

Layout

استفاده کنید.layout میتوانید از Containerبرای شکل دهی به فرزندان یک columnی به نام layoutمثال قیبل با استفاده از

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : 'column', items: [ //د مانند مثال قبلrادامه ک

Page 28: Extjs 4

http://armandar.com

Layout

updateLayout suspendLayout

Page 29: Extjs 4

http://armandar.com

Layoutانواع

absolute accordion anchor border card center column fit hbox table vbox

Page 30: Extjs 4

http://armandar.com

absolute layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : 'absolute', items: [ { xtype: 'panel', title: 'Panel 1', x: 12, y: 20, height: 250 }, { xtype: 'panel', title: 'Panel 2', x: 200, y: 150, height: 200 }, { xtype: 'panel', title: 'Panel 3', x: 400, y: 250, width: 150, height: 100 } ] });

Page 31: Extjs 4

http://armandar.com

accordion layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : 'accordion', items: [ { title: 'Item 1', html: 'Lorem ipsum dolor sit amet, consectetur ....‘ }, { title: 'Item 2', html: 'some content here‘ }, { title: 'Item 3', html: 'empty‘ } ] });

Page 32: Extjs 4

http://armandar.com

anchor layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : 'anchor', items: [ { title: 'Item 1', html: 'Item 1', anchor: '50%‘ }, { title: 'Item 2', html: 'Item 2', anchor: '-20 -200‘ }, { title: 'Item 3', html: 'Item 3', anchor: '-200‘ } ] });

Page 33: Extjs 4

http://armandar.com

border layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : 'border', items: [ { title: 'Item 1', html: 'Item 1', region: 'center‘ }, { title: 'Item 2', html: 'Item 2', region: 'east', width: 200 }, { title: 'Item 3', html: 'Item 3', region: 'south', height: 100 } ] });

Page 34: Extjs 4

http://armandar.com

card layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : 'card', defaultListenerScope: true, bbar: ['->', { itemId: 'btn-prev', text: 'Previous', handler: 'showPrevious', disabled: true }, { itemId: 'btn-next', text: 'Next', handler: 'showNext' } ], items: [ { index: 0, title: 'Item 1', html: 'Item 1' }, { index: 1, title: 'Item 2', html: 'Item 2' }, { index:2, title: 'Item 3', html: 'Item 3' } ], showNext: function () { this.navigate(1); }, showPrevious: function () { this.navigate(-1); }, navigate: function (incr) { …. } });

Page 35: Extjs 4

http://armandar.com

fit Layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : 'fit', bodyPadding: 20, items: [ { title: 'Item 1', html: 'Fills the container‘ } ] })

Page 36: Extjs 4

http://armandar.com

hbox layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : { type: 'hbox', pack: 'start', align: 'stretch', }, items: [ { title: 'Item 1', html: 'Item 1', flex: 1 }, { title: 'Item 2', html: 'Item 2', width: 100 }, { title: 'Item 3', html: 'Item 3', flex: 2 } ] })

Page 37: Extjs 4

http://armandar.com

table layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : { type: 'table', columns: 3, tableAttrs: { style: { width: '100%' } } }, items: [ { rowspan: 3, title: 'Item 1', html: 'Item 1' }, { title: 'Item 2', html: 'Item 2' }, { title: 'Item 3', rowspan: 2, html: 'Item 3' }, { title: 'Item 4', html: 'Item 4' }, { title: 'Item 5', html: 'Item 5' }, { title: 'Item 6', html: 'Item 6' }, { title: 'Item 7', html: 'Item 7' } ] });

Page 38: Extjs 4

http://armandar.com

vbox layout

Ext.create('Ext.panel.Panel', { renderTo : Ext.getBody(), width : 700, height : 400, layout : { type: 'vbox', pack: 'start', align: 'stretch‘ }, items: [ { title: 'Item 1', html: 'Item 1', flex: 1 }, { title: 'Item 2', html: 'Item 2', height: 100 }, { title: 'Item 3', html: 'Item 3', flex: 2 } ] });