第二章:Ext.js高级组件

grid组件

普通方式

表格面板类Ext.grid.Panel

  • xtype(别名):gridpanel、grid

    • title标题、renderTo渲染至、width宽、height高
    • frame : Boolean 是否填充渲染gridpanel
    • forceFit : true 列是否自动填充
    • store : store 数据集
    • tbar: []
      • 头部工具栏
    • dockedItems : Object/Array
      • 可定位的停靠工具条(上、下、左、右)
    • selType : ‘checkboxmodel’
      • 选择框选择模式
    • multiSelect :true
      • 是否允许多选
    • plugins 插件
    • columns : Array
      • 列模式(Ext.grid.column.Columnxtype: gridcolumn)

        • text : String 列标题
        • dataIndex : String 和Model列对应
        • sortable : true 是否可以分类
        • field:
          • 可编辑字段配置
      • getStore
      • ownerCt返回父级
  • grid案例
    • gridDemo.js文件代码

      1. Ext.QuickTips.init(); //初始化提示
      2. //// 创建表格面板
      3. var grid = Ext.create("Ext.grid.Panel",{
      4. title : 'Grid Demo',
      5. frame : true, //面板渲染
      6. //forceFit : true, //自动填充列空白处(4.0的选择框有空隙问题时指定宽度)
      7. width : 600,
      8. height: 280,
      9. columns : [ //列模式
      10. {text:"Name",dataIndex:'name',width:100},
      11. {text:"age",dataIndex:'age',width:100},
      12. {text:"email",dataIndex:'email',width:350,
      13. field:{ //指定可编辑字段
      14. xtype:'textfield', //指定可编辑类型
      15. allowBlank:false
      16. }
      17. }
      18. ],
      19. tbar :[
      20. {xtype:'button',text:'添加',iconCls:'table_add'},
      21. {xtype:'button',text:'删除',iconCls:'table_remove',
      22. handler:function(o){
      23. //var gird = o.findParentByType("gridpanel"); //获取父级
      24. var gird = o.ownerCt.ownerCt; //获取删除按钮的父级的父级
      25. // 获取选中数据集
      26. var data = gird.getSelectionModel().getSelection();
      27. if(data.length == 0){
      28. Ext.Msg.alert("提示","请选择数据");
      29. }else{
      30. //// 根据name得到数据
      31. var st = gird.getStore(); //获取数据集
      32. var ids = []; //存储被选中数据的name集合
      33. Ext.Array.each(data,function(record){
      34. ids.push(record.get('name'));
      35. })
      36. //// 后台操作(delete)、前端操作DOM进行删除(ExtJs)
      37. Ext.Ajax.request({
      38. url:'/extjs/extjs!deleteData.action',
      39. params:{ids:ids.join(",")}, //指定要删除数据的name集合
      40. method:'POST',
      41. timeout:2000, //设定响应等待时间
      42. success:function(response,opts){
      43. Ext.Array.each(data,function(record){
      44. st.remove(record); //从store中删除该条记录
      45. })
      46. }
      47. })
      48. }
      49. }
      50. },
      51. {xtype:'button',text:'修改',iconCls:'table_edit'},
      52. {xtype:'button',text:'查看',iconCls:'table_comm'}
      53. ],
      54. dockedItems :[{ //可定位的停靠工具条
      55. xtype:'pagingtoolbar', //分页工具条
      56. store:Ext.data.StoreManager.lookup('s_user'), //指定store
      57. dock:'bottom',
      58. displayInfo:true //是否展示信息(eg:条数)
      59. }],
      60. plugins:[ //配置可编辑单元格插件实现grid的编辑
      61. Ext.create("Ext.grid.plugin.CellEditing",{
      62. clicksToEdit : 1 //点击N次进入编辑
      63. })
      64. ],
      65. selType:'checkboxmodel', //设定选择模式
      66. multiSelect:true, //允许多选
      67. renderTo :Ext.getBody(),
      68. // 通过指定store的id在StoreManager获取store
      69. store : Ext.data.StoreManager.lookup('s_user')
      70. });
    • model.js文件代码
      1. //// Model类
      2. Ext.define("user",{
      3. extend:"Ext.data.Model",
      4. fields:[
      5. {name:'name',type:'string',sortable:true},
      6. {name:'age',type:'int',sortable:true},
      7. {name:'email',type:'string',sortable:true}
      8. ]
      9. });
      10. //// store类
      11. Ext.create("Ext.data.Store",{
      12. model:'user',
      13. storeId:'s_user', //指定了storeId后store由StoreManager自动管理
      14. proxy:{
      15. type:'ajax',
      16. url:'/extjs/extjs!getUserList.action',
      17. reader:{
      18. type:'json',
      19. root:'root'
      20. },
      21. writer:{
      22. type:'json'
      23. }
      24. },
      25. autoLoad:true //自动加载数据
      26. });

MVC方式

  • extjs创建应用的方法

    • Ext.application();(Ext.app.Application类)

      1. Ext.application({
      2. name: 'MyApp',
      3. launch: function() {
      4. Ext.create('Ext.container.Viewport', {
      5. items: { html: 'My App'}
      6. });
      7. }
      8. });
    • Ext.app.Controller 控制器
    • Ext.ComponentQuery 组件查询(extjs4.0新特性)
    • Ext.container.Containerxtype: container类
  • grid组件的MVC实现
    • html文件代码中引入app.js文件

      1. <link rel="stylesheet"type="text/css" href="extjs/resources/css/ext-all.css" />
      2. <script type="text/javascript" src="extjs/bootstrap.js"></script>
      3. <script type="text/javascript" src="app.js"></script>
    • app.js文件代码
      1. Ext.onReady(function(){
      2. Ext.QuickTips.init();
      3. Ext.Loader.setConfig({ //执行加载
      4. enabled:true
      5. });
      6. Ext.application({
      7. name : 'AM', //应用名
      8. appFolder : "app", //应用目录
      9. launch:function(){ //当前页面加载完成后执行
      10. Ext.create('Ext.container.Viewport', { //创建Viewport
      11. layout:'auto', //自动填充布局
      12. items: {
      13. xtype: 'userlist', //view的别名
      14. title: 'Users',
      15. html : 'List of users will go here'
      16. }
      17. });
      18. },
      19. controllers:['Users']
      20. });
      21. })
    • controller/Users.js文件代码
      1. Ext.define('AM.controller.Users', {
      2. extend: 'Ext.app.Controller',
      3. init:function(){
      4. this.control({ //控制事件等
      5. 'userlist button[id=delete]':{
      6. click:function(o){
      7. var gird = o.ownerCt.ownerCt;
      8. var data = gird.getSelectionModel().getSelection();
      9. if(data.length == 0){
      10. Ext.Msg.alert("提示","请选择数据");
      11. }else{
      12. //// 根据name得到数据
      13. var st = gird.getStore(); //获取数据集
      14. var ids = []; //存储被选中数据的name集合
      15. Ext.Array.each(data,function(record){
      16. ids.push(record.get('name'));
      17. })
      18. //// 后台操作(delete)、前端操作DOM进行删除(ExtJs)
      19. Ext.Ajax.request({
      20. url:'/extjs/extjs!deleteData.action',
      21. params:{ids:ids.join(",")}, //指定要删除数据的name集合
      22. method:'POST',
      23. timeout:2000, //设定响应等待时间
      24. success:function(response,opts){
      25. Ext.Array.each(data,function(record){
      26. st.remove(record); //从store中删除该条记录
      27. })
      28. }
      29. })
      30. }
      31. }
      32. }
      33. });
      34. },
      35. views:['List'],
      36. stores :["Users"],
      37. models :["User"]
      38. });
    • view/List.js文件代码
      1. Ext.define("AM.view.List",{
      2. extend:'Ext.grid.Panel',
      3. title : 'Grid Demo',
      4. alias: 'widget.userlist',
      5. frame : true, //面板渲染
      6. width : 600,
      7. height: 280,
      8. columns : [ //列模式
      9. {text:"Name",dataIndex:'name',width:100},
      10. {text:"age",dataIndex:'age',width:100},
      11. {text:"email",dataIndex:'email',width:350,
      12. field:{
      13. xtype:'textfield',
      14. allowBlank:false
      15. }
      16. }
      17. ],
      18. tbar :[
      19. {xtype:'button',text:'添加',iconCls:'table_add'},
      20. {xtype:'button',id:'delete',text:'删除',iconCls:'table_remove'},
      21. {xtype:'button',text:'修改',iconCls:'table_edit'},
      22. {xtype:'button',text:'查看',iconCls:'table_comm'}
      23. ],
      24. dockedItems :[{
      25. xtype:'pagingtoolbar',
      26. store:'Users',
      27. dock:'bottom',
      28. displayInfo:true
      29. }],
      30. plugins:[
      31. Ext.create("Ext.grid.plugin.CellEditing",{
      32. clicksToEdit : 2 //单击时会报错(ext.js的bug)
      33. })
      34. ],
      35. selType:'checkboxmodel', //设定选择模式
      36. multiSelect:true,
      37. store : 'Users',
      38. initComponent:function(){ //初始化组件,进行渲染
      39. this.callParent(arguments);
      40. }
      41. });
    • store/Users.js文件代码
      1. Ext.define('AM.store.Users', {
      2. extend: 'Ext.data.Store',
      3. model: 'AM.model.User', //define时的名
      4. storeId: 's_user',
      5. proxy:{
      6. type:'ajax',
      7. url:'/extjs/extjs!getUserList.action',
      8. reader: {
      9. type: 'json',
      10. root: 'root'
      11. },
      12. writer:{
      13. type:'json'
      14. }
      15. },
      16. autoLoad: true //自动加载数据(很关键)
      17. });
    • model/User.js文件代码
      1. Ext.define('AM.model.User', {
      2. extend: 'Ext.data.Model',
      3. fields: [
      4. {name: 'name', type: 'string',sortable : true},
      5. {name: 'age', type: 'int',sortable : true},
      6. {name: 'email', type: 'string',sortable : true}
      7. ]
      8. });

grid列模式

  • Ext.grid.column.Column

    • xtype: gridcolumn
  • Ext.grid.column.Action
    • 在表格中渲染一组图标按钮,并为其赋予某种功能
    • xtype: actioncolumn
      • altText:String 设置应用image元素上的alt
      • handler:function(view,rowindex,collndex,item,e);
      • icon:图标资源地址、iconCls:图标样式
      • items:多个图标的数组 (使用MVC时不建议使用)
      • stopSelection:设置是否单击选中
  • Ext.grid.column.Boolean
    • xtype: booleancolumn

      • falseText,trueText
  • Ext.grid.column.Date
    • xtype: datecolumn

      • format:’Y年m月的日’
  • Ext.grid.column.Number
    • xtype: numbercolumn

      • format:‘0,000’
  • Ext.grid.column.Template
    • xtype:’templatecolumn’,
    • tpl :”“
  • Ext.grid.RowNumberer
    • xtype: rownumberer
  • 数据字典
    • 业务数据字典

      • 风险等级,城市
    • 不变的数据字典
      • 男,女;是,否;血型
  • 案例
  • controller/Users.js文件代码
    1. Ext.define('AM.controller.Users', {
    2. extend: 'Ext.app.Controller',
    3. init:function(){
    4. this.control({ //控制事件等
    5. 'userlist button[id=delete]':{
    6. click:function(o){
    7. var gird = o.ownerCt.ownerCt;
    8. var data = gird.getSelectionModel().getSelection();
    9. if(data.length == 0){
    10. Ext.Msg.alert("提示","请选择数据");
    11. }else{
    12. //// 根据name得到数据
    13. var st = gird.getStore(); //获取数据集
    14. var ids = []; //存储被选中数据的name集合
    15. Ext.Array.each(data,function(record){
    16. ids.push(record.get('name'));
    17. })
    18. //// 后台操作(delete)、前端操作DOM进行删除(ExtJs)
    19. Ext.Ajax.request({
    20. url:'/extjs/extjs!deleteData.action',
    21. params:{ids:ids.join(",")}, //指定要删除数据的name集合
    22. method:'POST',
    23. timeout:2000, //设定响应等待时间
    24. success:function(response,opts){
    25. Ext.Array.each(data,function(record){
    26. st.remove(record); //从store中删除该条记录
    27. })
    28. }
    29. })
    30. }
    31. }
    32. },
    33. "userlist actioncolumn[id=delete]":{
    34. click : function(o,item,rowIndex,colIndex ,e){
    35. alert(rowIndex+" "+colIndex);
    36. }
    37. }
    38. });
    39. },
    40. views:['List'],
    41. stores :["Users"],
    42. models :["User"]
    43. });
  • view/List.js文件代码
    1. Ext.define("AM.view.List",{
    2. extend:'Ext.grid.Panel',
    3. title : 'Grid Demo',
    4. alias: 'widget.userlist',
    5. frame : true, //面板渲染
    6. width : 600,
    7. height: 280,
    8. columns : [ //列模式
    9. Ext.create("Ext.grid.RowNumberer",{}),
    10. {text:"Name",dataIndex:'name',width:100},
    11. {text:"age",dataIndex:'age',width:100},
    12. {text:"email",dataIndex:'email',width:200,
    13. field:{
    14. xtype:'textfield',
    15. allowBlank:false
    16. }
    17. },{
    18. text:'sex',
    19. dataIndex:'sex',
    20. width:50,
    21. DDName:'sy_sex',
    22. renderer:function(value){
    23. if(value){
    24. if(value == "女"){
    25. return "<font color='green'>"+value+"</font>"
    26. }else if(value == "男"){
    27. return "<font color='red'>"+value+"</font>"
    28. }
    29. }
    30. }
    31. },{
    32. text:'isIt',
    33. dataIndex:'isIt',
    34. xtype : "booleancolumn",
    35. width:50,
    36. trueText:'是',
    37. falseText:'不是'
    38. },{
    39. text:'birthday',
    40. dataIndex:'birthday',
    41. xtype : "datecolumn",
    42. width:150,
    43. format:'Y年m月d日'
    44. },{
    45. text:'deposit',
    46. dataIndex:'deposit',
    47. xtype:'numbercolumn',
    48. width:150,
    49. format:'0,000'
    50. },{
    51. text:'描述',
    52. xtype:'templatecolumn',
    53. tpl:'姓名是{name} 年龄是{age}',
    54. width:150
    55. },{
    56. text:'Action',
    57. xtype:'actioncolumn',
    58. id:'delete',
    59. icon:'app/view/image/table_delete.png',
    60. width:50
    61. }
    62. ],
    63. tbar :[
    64. {xtype:'button',text:'添加',iconCls:'table_add'},
    65. {xtype:'button',id:'delete',text:'删除',iconCls:'table_remove'},
    66. {xtype:'button',text:'修改',iconCls:'table_edit'},
    67. {xtype:'button',text:'查看',iconCls:'table_comm'}
    68. ],
    69. dockedItems :[{
    70. xtype:'pagingtoolbar',
    71. store:'Users',
    72. dock:'bottom',
    73. displayInfo:true
    74. }],
    75. plugins:[
    76. Ext.create("Ext.grid.plugin.CellEditing",{
    77. clicksToEdit : 2 //单击时会报错(ext.js的bug)
    78. })
    79. ],
    80. selType:'checkboxmodel', //设定选择模式
    81. multiSelect:true,
    82. store : 'Users',
    83. initComponent:function(){ //初始化组件,进行渲染
    84. this.callParent(arguments);
    85. }
    86. });
  • model/User.js文件代码
    1. Ext.define('AM.model.User', {
    2. extend: 'Ext.data.Model',
    3. fields: [
    4. {name: 'name', type: 'string',sortable : true},
    5. {name: 'age', type: 'int',sortable : true},
    6. {name: 'email', type: 'string',sortable : true},
    7. {name: 'birthday', type: 'string',sortable : true},
    8. {name: 'deposit', type: 'int',sortable : true},
    9. {name: 'isIt', type: 'string',sortable : true},
    10. {name: 'sex', type: 'string',sortable : true}
    11. ]
    12. });

grid选择模式

  • 根类

    • Ext.selection.Model
  • 重要方法
    • 撤销选择 deselect( Ext.data.Model/Index records, Boolean suppressEvent ) : void
    • 得到选择的数据getSelection( ) : Array
    • 得到最后被选择的数据getLastSelected( ) : void
    • 判断指定的数据是否被选择上isSelected( Record/Number record ) : Boolean
    • 选择指定的行selectRange( Ext.data.Model/Number startRow, Ext.data.Model/Number endRow, [Boolean keepExisting], Object dir ) : void
    • keepExisting true保持已选则的,false重新选择
  • 隐藏了一个单元格的选择模式
    • selType: ‘cellmodel’

      • 从这发现的Ext.grid.plugin.CellEditing
    • 重要方法
      • 得到被选择的单元格getCurrentPosition() Object
      • Ext.JSON.encode()
      • itemclick( Ext.view.View this, Ext.data.Model record, HTMLElement item, Number index, Ext.EventObject e, Object options )
      • selectByPosition({“row”:5,”column”:6})
        • 很实用,选择要特殊处理的数据
  • 多选框选择器Ext.selection.CheckboxModel
    • 重要方法

      • Ext.selection.RowModel

        • rowmodel 行选择器
    • 重要属性
      • multiSelect 允许多选
      • simpleSelect 单选选择功能
      • enableKeyNav 允许使用键盘

Grid特性

  • Ext.grid.feature.Feature
  • 表格的行体Ext.grid.feature.RowBody

    • 重要方法

      • getAdditionalData( Object data, Number idx, Ext.data.Model record, Object orig ) : void

        • 如果要展示这个面板那么必须复写这个方法

          1. features: [
          2. Ext.create("Ext.grid.feature.RowBody",{
          3. getAdditionalData:function(data,idx,record,orig){ ...... }
          4. })
          5. ],
        • 必须返回行体的对象
          1. var headerCt = this.view.headerCt,
          2. colspan = headerCt.getColumnCount();
          3. return {
          4. rowBody: "",
          5. rowBodyCls: this.rowBodyCls,
          6. rowBodyColspan: colspan
          7. };
  • Ext.grid.feature.AbstractSummary

    • Ext.grid.feature.Summary
    • 第一步 
      1. features: [{
      2. ftype: 'summary'
      3. }],
    • 第二步
      • columns中配置summaryType: ‘count’, (count,sum,min,max,average)

        1. summaryRenderer: function(value, summaryData, dataIndex) {
        2. return Ext.String.format(' : '+value);
        3. }
  • Ext.grid.feature.Grouping

    • 在store中设置可以分组的属性

      • groupField : ‘’
    • 在view中增加代码
      1. Ext.create("Ext.grid.feature.Grouping",{
      2. groupByText : "职业分组",
      3. groupHeaderTpl : "职业{name} 一共{rows.length}人",
      4. showGroupsText : "展示分组",
      5. startCollapsed : true
      6. }
    • 重要事件
      • groupclick
      • groupdblclick
      • groupcontextmenu
      • groupexpand
      • groupcollapse
  • 扩展

    • Ext.grid.feature.GroupingSummary
    • Ext.grid.feature.Chunking
  • 代码

    • app.js

      1. Ext.onReady(function(){
      2. Ext.QuickTips.init();
      3. Ext.Loader.setConfig({
      4. enabled:true
      5. });
      6. Ext.application({
      7. name : 'AM',//应用的名字
      8. appFolder : "app",//应用的目录
      9. launch:function(){//当前页面加载完成执行的函数
      10. Ext.create('Ext.container.Viewport', { //简单创建一个试图
      11. layout:'auto',//自动填充布局
      12. items: {
      13. xtype: 'userlist',
      14. title: 'Users',
      15. html : 'List of users will go here'
      16. }
      17. });
      18. },
      19. controllers:[
      20. 'Users'
      21. ]
      22. });
      23. })
    • controller/Users.js
      1. Ext.define('AM.controller.Users', {
      2. extend: 'Ext.app.Controller',
      3. init:function(){
      4. this.control({
      5. 'userlist':{
      6. itemclick:function(View, record, item, index, e, options ){
      7. var sm = View.getSelectionModel();//.getSelection();
      8. //alert(Ext.JSON.encode(sm.getCurrentPosition()));
      9. sm.selectByPosition({"row":1,"column":2});
      10. }
      11. },
      12. 'userlist button[id=selection]':{
      13. click:function(o){
      14. var gird = o.ownerCt.ownerCt;
      15. var sm = gird.getSelectionModel();
      16. //sm.deselect(0);
      17. //alert(sm.getLastSelected().get('name'))
      18. //alert(sm.isSelected(0));
      19. //sm.selectRange(1,2,true);
      20. sm.selectByPosition({"row":2,"column":3});
      21. }
      22. },
      23. 'userlist button[id=del]':{
      24. click:function(o){
      25. var gird = o.ownerCt.ownerCt;
      26. var data = gird.getSelectionModel().getSelection();
      27. if(data.length == 0){
      28. Ext.Msg.alert("提示","您最少要选择一条数据");
      29. }else{
      30. //1.先得到ID的数据(name)
      31. var st = gird.getStore();
      32. var ids = [];
      33. Ext.Array.each(data,function(record){
      34. ids.push(record.get('name'));
      35. })
      36. //2.后台操作(delet)
      37. Ext.Ajax.request({
      38. url:'/extjs/extjs!deleteData.action',
      39. params:{ids:ids.join(",")},
      40. method:'POST',
      41. timeout:2000,
      42. success:function(response,opts){
      43. Ext.Array.each(data,function(record){
      44. st.remove(record);
      45. })
      46. }
      47. })
      48. //3.前端操作DOM进行删除(ExtJs)
      49. }
      50. }
      51. },
      52. "userlist actioncolumn[id=delete]":{
      53. click : function(o,item,rowIndex,colIndex ,e){
      54. alert(rowIndex+" "+colIndex);
      55. }
      56. }
      57. });
      58. },
      59. views:[
      60. 'List'
      61. ],
      62. stores :[
      63. "Users"
      64. ],
      65. models :[
      66. "User"
      67. ]
      68. });
    • model/User.js
      1. Ext.define('AM.model.User', {
      2. extend: 'Ext.data.Model',
      3. fields: [
      4. {name: 'name', type: 'string',sortable : true},
      5. {name: 'age', type: 'int',sortable : true},
      6. {name: 'email', type: 'string',sortable : true},
      7. {name: 'birthday', type: 'string',sortable : true},
      8. {name: 'deposit', type: 'int',sortable : true},
      9. {name: 'isIt', type: 'string',sortable : true},
      10. {name: 'sex', type: 'string',sortable : true}
      11. ]
      12. });
    • store/Users.js
      1. Ext.define('AM.store.Users', {
      2. extend: 'Ext.data.Store',
      3. model: 'AM.model.User',
      4. storeId: 's_user',
      5. groupField : 'sex',
      6. proxy:{
      7. type:'ajax',
      8. url:'/extjs/extjs!getUserList.action',
      9. reader: {
      10. type: 'json',
      11. root: 'topics'
      12. },writer:{
      13. type:'json'
      14. }
      15. },
      16. autoLoad: true //
      17. });
    • view/List.js
      1. Ext.define("AM.view.List",{
      2. extend:'Ext.grid.Panel',
      3. title : 'Grid Demo',//标题
      4. alias: 'widget.userlist',
      5. frame : true,//面板渲染
      6. width : 1100,
      7. height: 450,
      8. features: [
      9. Ext.create("Ext.grid.feature.RowBody",{
      10. getAdditionalData: function(data, idx, record, orig) {
      11. var headerCt = this.view.headerCt,
      12. colspan = headerCt.getColumnCount();
      13. return {
      14. rowBody: record.get('email'),
      15. rowBodyCls: this.rowBodyCls,
      16. rowBodyColspan: colspan
      17. };
      18. }
      19. }),{
      20. ftype: 'summary'
      21. },Ext.create("Ext.grid.feature.Grouping",{
      22. groupByText : "性别分组",
      23. groupHeaderTpl : "性别{name} 一共{rows.length}人",
      24. showGroupsText : "展示分组"
      25. })
      26. ],
      27. columns : [ //列模式
      28. Ext.create("Ext.grid.RowNumberer",{}),
      29. {text:"Name",dataIndex:'name',width:100},
      30. {text:"age",dataIndex:'age',width:100,
      31. summaryType:'average',
      32. summaryRenderer: function(value, summaryData, dataIndex) {
      33. return Ext.util.Format.number(value,"00.0")
      34. }
      35. },
      36. {text:"email",dataIndex:'email',width:200,
      37. field:{
      38. xtype:'textfield',
      39. allowBlank:false
      40. }
      41. },{
      42. text:'sex',
      43. dataIndex:'sex',
      44. width:50,
      45. DDName:'sy_sex',
      46. renderer:function(value){
      47. if(value){
      48. if(value == "女"){
      49. return "<font color='green'>"+value+"</font>"
      50. }else if(value == "男"){
      51. return "<font color='red'>"+value+"</font>"
      52. }
      53. }
      54. }
      55. },{
      56. text:'isIt',
      57. dataIndex:'isIt',
      58. xtype : "booleancolumn",
      59. width:50,
      60. trueText:'是',
      61. falseText:'不是'
      62. },{
      63. text:'birthday',
      64. dataIndex:'birthday',
      65. xtype : "datecolumn",
      66. width:150,
      67. format:'Y年m月d日'
      68. },{
      69. text:'deposit',
      70. dataIndex:'deposit',
      71. xtype:'numbercolumn',
      72. width:150,
      73. format:'0,000'
      74. },{
      75. text:'描述',xtype:'templatecolumn',
      76. tpl:'姓名是{name} 年龄是{age}',
      77. width:150
      78. },{
      79. text:'Action',xtype:'actioncolumn',
      80. id:'delete',
      81. icon:'app/view/image/table_delete.png',
      82. width:50//,
      83. // items :[
      84. // {},{}
      85. // ]
      86. // handler:function(grid,row,col){
      87. // alert(row+" "+col);
      88. // }
      89. }
      90. ],
      91. tbar :[
      92. {xtype:'button',text:'添加',iconCls:'table_add'},
      93. {xtype:'button',id:'del',text:'删除',iconCls:'table_remove'},
      94. {xtype:'button',text:'修改',iconCls:'table_edit'},
      95. {xtype:'button',text:'查看',iconCls:'table_comm'},
      96. {xtype:'button',id:'selection',text:'selection',iconCls:'table_comm'}
      97. ],
      98. dockedItems :[{
      99. xtype:'pagingtoolbar',
      100. store:'Users',
      101. dock:'bottom',
      102. displayInfo:true
      103. }],
      104. plugins:[
      105. Ext.create("Ext.grid.plugin.CellEditing",{
      106. clicksToEdit : 2
      107. })
      108. ],
      109. //selType:'rowmodel',//设定选择模式
      110. selType:'cellmodel',
      111. //multiSelect:true,//运行多选
      112. //enableKeyNav :true,
      113. store : 'Users',
      114. initComponent:function(){
      115. this.callParent(arguments);
      116. }
      117. });

grid插件

  • 可编辑插件

    • 根类Ext.grid.plugin.Editing
    • Ext.grid.plugin.CellEditing
      • 保存修改的两种办法

        • 设立保存按钮,用户单击的时候保存数据

          1. st.sync();
          2. var records = st.getUpdatedRecords();
          3. Ext.Array.each(records,function(model){
          4. model.commit();
          5. });
        • 注册edit事件
          • e.record.commit();
    • Ext.grid.plugin.RowEditing
      • 4.0.1a版本不推荐这个功能

        1. Ext.create('Ext.grid.plugin.RowEditing', {
        2. clicksToEdit: 1
        3. })
  • 表格拖拽Ext.grid.plugin.DragDrop
    • 注意:配置有变化

      1. viewConfig:{
      2. plugins:[
      3. Ext.create('Ext.grid.plugin.DragDrop', {
      4. ddGroup:'ddTree', //拖放组的名称
      5. dragGroup :'userlist', //拖拽组名称
      6. dropGroup :'userlist' //释放租名称
      7. enableDrag:true, //是否启用
      8. enableDrop:true
      9. })]
      10. }
    • 处理事件
      1. listeners: {
      2. drop: function(node, data, dropRec, dropPosition) {
      3. var st = this.getStore();
      4. for(i=0;i<st.getCount();i++){
      5. st.getAt(i).set('index',i+1);
      6. }
      7. }
      8. }
  • 分页组件Ext.toolbar.Paging
    1. dockedItems: [{
    2. xtype: 'pagingtoolbar',
    3. store: store,
    4. dock: 'bottom',
    5. displayInfo: true
    6. }],
    • 第二种分页的形式

      1. Ext.Loader.setPath('Ext.ux', '../../../extjs4/examples/ux');
      2. Ext.require([
      3. 'Ext.ux.data.PagingMemoryProxy',
      4. 'Ext.ux.SlidingPager'
      5. ]);
      6. bbar: Ext.create('Ext.PagingToolbar', {
      7. pageSize: 10,
      8. store: store,
      9. displayInfo: true,
      10. plugins: Ext.create('Ext.ux.SlidingPager', {}) ---- 重点
      11. })
  • 属性配置框面板Ext.grid.property.Grid
    • 做自动生成功能时可以考虑用
  • 关于表格的其他东西
    • 列锁定

      • {text:”age”,dataIndex:’age’,width:100,locked:true},
    • 复杂表头
      1. {
      2. text:'other',columns:[
      3. {text:"age",dataIndex:'age',width:100,locked : true},
      4. {text:"int",dataIndex:'index',width:100}]
      5. }
    • 字段过滤
      1. Ext.require([
      2. 'Ext.ux.grid.FiltersFeature'
      3. ]);
      4. //创建类
      5. Ext.define("AM.class.filters",{
      6. alias: 'widget.filters',
      7. ftype: 'filters',
      8. encode: false,
      9. local: true,
      10. filters: [{
      11. type: 'boolean',
      12. dataIndex: 'visible'
      13. }
      14. ]
      15. })
      16. //view层中添加
      17. features: [Ext.create("AM.class.filters")],
      18. 列中{filterable: true,text:"age",dataIndex:'age',width:100,filter: {type: 'numeric'}},
  • 代码
    • app.js

      1. Ext.onReady(function(){
      2. Ext.QuickTips.init();
      3. Ext.Loader.setConfig({
      4. enabled:true
      5. });
      6. Ext.Loader.setPath('Ext.ux', '../../../extjs4/examples/ux');
      7. Ext.require([
      8. 'Ext.ux.data.PagingMemoryProxy',
      9. 'Ext.ux.SlidingPager',
      10. 'Ext.ux.grid.FiltersFeature'
      11. ]);
      12. Ext.application({
      13. name : 'AM',
      14. appFolder : "app",
      15. launch:function(){
      16. Ext.create('Ext.container.Viewport', {
      17. layout:'auto',
      18. items:[{
      19. xtype: 'userlist',
      20. title: 'Users'
      21. },{
      22. xtype:'proList'
      23. }]
      24. });
      25. },
      26. controllers:[
      27. 'Users'
      28. ]
      29. });
      30. })
    • controller/Users.js
      1. Ext.define('AM.controller.Users', {
      2. extend: 'Ext.app.Controller',
      3. init:function(){
      4. this.control({
      5. 'userlist':{
      6. edit:function(editor,e,options){
      7. //Model
      8. //e.record.commit();
      9. }
      10. },
      11. 'userlist button[id=save]':{
      12. click:function(o){
      13. var gird = o.ownerCt.ownerCt;
      14. var st = gird.getStore();
      15. st.sync();//数据与后台同步
      16. var records = st.getUpdatedRecords();
      17. Ext.Array.each(records,function(model){
      18. model.commit();
      19. });
      20. }
      21. },
      22. 'userlist button[id=delete]':{
      23. click:function(o){
      24. var gird = o.ownerCt.ownerCt;
      25. var data = gird.getSelectionModel().getSelection();
      26. if(data.length == 0){
      27. Ext.Msg.alert("提示","您最少要选择一条数据");
      28. }else{
      29. //1.先得到ID的数据(name)
      30. var st = gird.getStore();
      31. var ids = [];
      32. Ext.Array.each(data,function(record){
      33. ids.push(record.get('name'));
      34. })
      35. //2.后台操作(delet)
      36. Ext.Ajax.request({
      37. url:'/extjs/extjs!deleteData.action',
      38. params:{ids:ids.join(",")},
      39. method:'POST',
      40. timeout:2000,
      41. success:function(response,opts){
      42. Ext.Array.each(data,function(record){
      43. st.remove(record);
      44. })
      45. }
      46. })
      47. //3.前端操作DOM进行删除(ExtJs)
      48. }
      49. }
      50. }
      51. });
      52. },
      53. views:[
      54. 'proerty',
      55. 'List'
      56. ],
      57. stores :[
      58. "Users"
      59. ],
      60. models :[
      61. "User"
      62. ]
      63. });
    • model/User.js
      1. Ext.define('AM.model.User', {
      2. extend: 'Ext.data.Model',
      3. fields: [
      4. {name: 'name', type: 'string',sortable : true},
      5. {name: 'age', type: 'int',sortable : true},
      6. {name: 'email', type: 'string',sortable : true},
      7. {name: 'index', type: 'int',sortable : true}
      8. ]
      9. });
    • store/Users.js
      1. Ext.define('AM.store.Users', {
      2. extend: 'Ext.data.Store',
      3. model: 'AM.model.User',
      4. storeId: 's_user',
      5. proxy:{
      6. type:'ajax',
      7. url:'/extjs/extjs!getUserList.action',
      8. reader: {
      9. type: 'json',
      10. root: 'topics'
      11. },writer:{
      12. type:'json'
      13. }
      14. },
      15. autoLoad: true
      16. });
    • view/List.js
      1. Ext.define("AM.view.List",{
      2. extend:'Ext.grid.Panel',
      3. title : 'Grid Demo',//标题
      4. alias: 'widget.userlist',
      5. frame : true,//面板渲染
      6. width : 500,
      7. height: 380,
      8. columns : [ //列模式
      9. //{text:"Name",dataIndex:'name',width:100,locked:true},
      10. {text:"Name",dataIndex:'name',width:100},
      11. //{text:'others',columns:[
      12. {text:"age",dataIndex:'age',width:100,filterable: true,filter: {type: 'numeric'}},
      13. {text:"email",dataIndex:'email',width:250,
      14. field:{
      15. xtype:'textfield',
      16. allowBlank:false
      17. }
      18. },{
      19. text:'index',dataIndex:'index',width:100
      20. }
      21. //]}
      22. ],
      23. features: [Ext.create("AM.util.filters")],
      24. tbar :[
      25. {xtype:'button',text:'添加',iconCls:'table_add'},
      26. {xtype:'button',id:'delete',text:'删除',iconCls:'table_remove'},
      27. {xtype:'button',text:'修改',iconCls:'table_edit'},
      28. {xtype:'button',text:'查看',iconCls:'table_comm'},
      29. {xtype:'button',text:'save',id:'save',iconCls:'table_comm'}
      30. ],
      31. dockedItems :[{
      32. xtype:'pagingtoolbar',
      33. store:'Users',
      34. dock:'bottom',
      35. displayInfo:true,
      36. plugins: Ext.create('Ext.ux.SlidingPager', {})
      37. }],
      38. //plugins:[
      39. // Ext.create("Ext.grid.plugin.CellEditing",{
      40. // clicksToEdit : 2
      41. // })
      42. // Ext.create('Ext.grid.plugin.RowEditing', {
      43. // clicksToEdit: 1
      44. // })
      45. //],
      46. viewConfig:{
      47. plugins:[
      48. Ext.create('Ext.grid.plugin.DragDrop', {
      49. ddGroup:'ddTree', //拖放组的名称
      50. dragGroup :'userlist', //拖拽组名称
      51. dropGroup :'userlist', //释放租名称
      52. enableDrag:true, //是否启用
      53. enableDrop:true
      54. })],
      55. listeners: {
      56. drop: function(node, data, dropRec, dropPosition) {
      57. var st = this.getStore();
      58. for(i=0;i<st.getCount();i++){
      59. st.getAt(i).set('index',i+1);
      60. }
      61. }
      62. }
      63. },
      64. //selType:'checkboxmodel',//设定选择模式
      65. //multiSelect:true,//运行多选
      66. store : 'Users',
      67. initComponent:function(){
      68. this.callParent(arguments);
      69. }
      70. });
    • view/dd.js
      1. Ext.define("AM.view.dd",{
      2. extend:'Ext.grid.plugin.DragDrop',
      3. alias: 'widget.dd',
      4. ddGroup:'ddTree',
      5. dragGroup :'userlist',
      6. dropGroup :'userlist',
      7. initComponent:function(){
      8. this.callParent(arguments);
      9. }
      10. })
    • view/proerty.js
      1. Ext.define("AM.view.proerty",{
      2. extend:'Ext.grid.property.Grid',
      3. title: 'Properties Grid',
      4. alias: 'widget.proList',
      5. width: 300,
      6. //自定义渲染的函数
      7. customRenderers :{
      8. 'boy':function(value){
      9. return value?'是':'否'
      10. },
      11. 'emial-width':function(value){
      12. return value;
      13. }
      14. },
      15. source: {
      16. 'boy':false,
      17. 'emial-width':'100'
      18. }
      19. })
    • util/filters.js
      1. Ext.define("AM.util.filters",{
      2. alias: 'widget.filters',
      3. ftype: 'filters',
      4. encode: false,
      5. local: true,
      6. filters: [{
      7. type: 'boolean',
      8. dataIndex: 'visible'
      9. }
      10. ]
      11. })

tree组件

  • 类结构

    • Ext.panel.Panel

      • Ext.panel.Table

        • Ext.tree.Panel

          • 和grid完全一样
  • 快速实现一个demo
    • 主要配置项

      • title、width、height、renderTo
      • root 控制根节点(Ext.data.Model/Ext.data.NodeInterface)
      • animate : Boolean 控制收起和展开是否有动画效果
      • store: store 数据集合
    • 重要事件
      • itemclick
  • Ext.data.TreeStore
  • 代码
    • app.js

      1. Ext.onReady(function(){
      2. Ext.QuickTips.init();
      3. Ext.Loader.setConfig({
      4. enabled:true
      5. });
      6. Ext.application({
      7. name : 'AM',
      8. appFolder : "app",
      9. launch:function(){
      10. Ext.create('Ext.container.Viewport', {
      11. layout:'auto',
      12. items: {
      13. xtype: 'deptTree'
      14. }
      15. });
      16. },
      17. controllers:[
      18. 'deptController'
      19. ]
      20. });
      21. })
    • controller/deptController.js
      1. Ext.define('AM.controller.deptController', {
      2. extend: 'Ext.app.Controller',
      3. init:function(){
      4. this.control({
      5. "deptTree button[id=allopen]":{
      6. click:function(b,e){
      7. var tree = b.ownerCt.ownerCt;
      8. tree.expandAll();
      9. }
      10. },
      11. "deptTree button[id=allclose]":{
      12. click:function(b,e){
      13. var tree = b.ownerCt.ownerCt;
      14. tree.collapseAll();
      15. }
      16. },
      17. "deptTree button[id=add]":{
      18. click:function(b,e){
      19. var tree = b.ownerCt.ownerCt;
      20. var nodes = tree.getChecked();
      21. if(nodes.length == 1){
      22. var node = nodes[0];
      23. node.appendChild({
      24. checked:true,
      25. text:'技术架构组',
      26. id : '0103',
      27. leaf:true
      28. });
      29. }else{
      30. alert("请您选择一个节点");
      31. }
      32. }
      33. },
      34. "deptTree":{
      35. itemclick:function(tree,record,item,index,e,options){
      36. alert(record.get('id'));
      37. }
      38. }
      39. });
      40. },
      41. views:[
      42. 'deptView'
      43. ],
      44. stores :[
      45. 'deptStore'
      46. ],
      47. models :[
      48. ]
      49. });
    • store/deptStore.js
      1. Ext.define("AM.store.deptStore",{
      2. extend:'Ext.data.TreeStore',
      3. defaultRoodId:'root',
      4. proxy:{
      5. type:'ajax',
      6. url:'/extjs/extjs!getDept.action',
      7. reader:'json',
      8. autoLoad:true
      9. }
      10. });
    • view/deptView.js
      1. Ext.define("AM.view.deptView",{
      2. extend:'Ext.tree.Panel',
      3. alias: 'widget.deptTree',
      4. title : '部门树形',
      5. width : 250,
      6. height: 300,
      7. padding : '5 3 3 10',
      8. rootVisible : false,//控制显隐的属性
      9. dockedItems:[{
      10. xtype:'toolbar',
      11. dock:'left',
      12. //ui:'footer',
      13. items:[
      14. {xtype:'button',text:'add',id:'add'},
      15. {xtype:'button',text:'copy',id:'copy'},
      16. {xtype:'button',text:'delete',id:'delete'}
      17. ]
      18. },{
      19. xtype:'toolbar',
      20. items:[{
      21. xtype:'button',
      22. id:'allopen',
      23. text:'展开全部'
      24. },{
      25. xtype:'button',
      26. id:'allclose',
      27. text:'收起全部'
      28. }]
      29. }],
      30. store:'deptStore'
      31. // root:{
      32. // text:'root',
      33. // id : '0',
      34. // leaf:false,
      35. // children:[{
      36. // text:'技术部门',
      37. // checked:false,
      38. // id : '01',
      39. // leaf:false,
      40. // children:[{
      41. // checked:false,
      42. // text:'研发部',
      43. // id : '0101',
      44. // leaf:true
      45. // },{
      46. // checked:false,
      47. // text:'实施部',
      48. // id : '0102',
      49. // leaf:true
      50. // }]
      51. // },{
      52. // text:'后勤部门',
      53. // id : '02',
      54. // checked:false,
      55. // leaf:false,
      56. // children:[{
      57. // text:'人事部',
      58. // id : '0201',
      59. // checked:false,
      60. // leaf:true
      61. // },{
      62. // text:'行政部',
      63. // id : '0202',
      64. // checked:false,
      65. // leaf:true
      66. // }]
      67. // }]
      68. // }
      69. });
  • 树形的拖拽
    • Ext.tree.ViewDDPlugin

      • alias: ‘plugin.treeviewdragdrop’,

        1. viewConfig:{
        2. plugins :{
        3. ptype:'treeviewdragdrop'
        4. }
        5. },
    • 事件
      1. listeners: {
      2. drop: function(node, data, dropRec, dropPosition) {},
      3. beforedrop:function(node,data,overModel,dropPosition,dropFunction,options ){ }
      4. }
    • 模拟拷贝和黏贴
    • 删除操作
    • 多列树
    • 单击树形根节点子节点也被选中
    • 代码
    • app.js
      1. Ext.onReady(function(){
      2. Ext.QuickTips.init();
      3. Ext.Loader.setConfig({
      4. enabled:true
      5. });
      6. Ext.application({
      7. name : 'AM',
      8. appFolder : "app",
      9. launch:function(){
      10. Ext.create('Ext.container.Viewport', {
      11. layout:'auto',
      12. items: {
      13. xtype: 'deptTree'
      14. }
      15. });
      16. },
      17. controllers:[
      18. 'deptController'
      19. ]
      20. });
      21. })
    • controller/deptController.js
      1. Ext.define('AM.controller.deptController', {
      2. extend: 'Ext.app.Controller',
      3. init:function(){
      4. this.control({
      5. 'deptTree':{
      6. checkchange : function(node,checked,options){
      7. if(node.data.leaf == false){//不是叶子
      8. if(checked){
      9. //打开节点
      10. node.expand();
      11. //遍历孩子
      12. node.eachChild(function(n){
      13. n.data.checked = true;
      14. n.updateInfo({checked:true});
      15. })
      16. }else{
      17. node.expand();
      18. node.eachChild(function(n){
      19. n.data.checked = false;
      20. n.updateInfo({checked:false});
      21. })
      22. }
      23. }else{//单击叶子
      24. if(!checked){
      25. node.parentNode.data.checked = false;
      26. node.parentNode.updateInfo({checked:false});
      27. }
      28. }
      29. }
      30. },
      31. 'deptTree button[id=delete]':{
      32. click:function(b,e){
      33. var tree = b.ownerCt.ownerCt;
      34. var nodes = tree.getChecked();
      35. for(i=0;i<nodes.length;i++){
      36. nodes[i].remove(true);
      37. }
      38. }
      39. },
      40. 'deptTree button[id=copy]':{
      41. click:function(b,e){
      42. var tree = b.ownerCt.ownerCt;
      43. //得到数据集合
      44. var nodes = tree.getChecked();
      45. if(nodes.length>0){
      46. //把数据放到剪切板中
      47. tree.setCopyNodes(Ext.clone(nodes));
      48. alert("拷贝"+nodes.length+"个节点");
      49. for(i=0;i<nodes.length;i++){
      50. nodes[i].data.checked = false;
      51. nodes[i].updateInfo();
      52. }
      53. }
      54. }
      55. },
      56. "deptTree button[id=paste]":{
      57. click:function(b,e){
      58. var tree = b.ownerCt.ownerCt;
      59. //被追加孩子的节点集合
      60. var checkednodes = tree.getChecked();
      61. if(checkednodes.length == 1){
      62. //被追加孩子的节点
      63. var node = checkednodes[0];
      64. //去剪切板中区数据
      65. var nodes = tree.getCopyNodes();
      66. if(nodes.length>0){
      67. for(i=0;i<nodes.length;i++){
      68. var n = nodes[i].data;
      69. n['id'] = n['id']+'1';
      70. node.appendChild(n);
      71. }
      72. }
      73. }else{
      74. alert("剪切板中无数据或者你没有选择要追加孩子的节点");
      75. }
      76. }
      77. },
      78. "deptTree button[id=allopen]":{
      79. click:function(b,e){
      80. var tree = b.ownerCt.ownerCt;
      81. tree.expandAll();
      82. }
      83. },
      84. "deptTree button[id=allclose]":{
      85. click:function(b,e){
      86. var tree = b.ownerCt.ownerCt;
      87. tree.collapseAll();
      88. }
      89. },
      90. "deptTree button[id=add]":{
      91. click:function(b,e){
      92. var tree = b.ownerCt.ownerCt;
      93. var nodes = tree.getChecked();
      94. if(nodes.length == 1){
      95. var node = nodes[0];
      96. node.appendChild({
      97. checked:true,
      98. text:'技术架构组',
      99. id : '0103',
      100. leaf:true
      101. });
      102. }else{
      103. alert("请您选择一个节点");
      104. }
      105. }
      106. }//,
      107. // "deptTree":{
      108. // itemclick:function(tree,record,item,index,e,options){
      109. // alert(record.get('id'));
      110. // }
      111. // }
      112. });
      113. },
      114. views:[
      115. 'deptView'
      116. ],
      117. stores :[
      118. 'deptStore'
      119. ],
      120. models :[
      121. 'deptModel'
      122. ]
      123. });
    • model/deptModel.js
      1. Ext.define('AM.model.deptModel', {
      2. extend: 'Ext.data.Model',
      3. fields: [
      4. {name: 'text', type: 'string',sortable : true},
      5. {name: 'id', type: 'string',sortable : true}
      6. ]
      7. });
    • store/deptStore.js
      1. Ext.define("AM.store.deptStore",{
      2. extend:'Ext.data.TreeStore',
      3. defaultRoodId:'root',
      4. model:'AM.model.deptModel',
      5. proxy:{
      6. type:'ajax',
      7. url:'/extjs/extjs!getDept.action',
      8. reader:'json',
      9. autoLoad:true
      10. }
      11. });
    • view/deptView.js
      1. Ext.define("AM.view.deptView",{
      2. extend:'Ext.tree.Panel',
      3. alias: 'widget.deptTree',
      4. title : '部门树形',
      5. width : 350,
      6. height: 300,
      7. padding : '5 3 3 10',
      8. rootVisible : false,//控制显隐的属性
      9. config:{
      10. copyNodes:''//他充当剪切板的作用
      11. },
      12. columns:[
      13. {
      14. xtype:'treecolumn',
      15. text:'text',
      16. writh:150,
      17. dataIndex:'text'
      18. },{
      19. text:'info',
      20. dataIndex:'id'
      21. }
      22. ],
      23. viewConfig:{
      24. plugins :{
      25. ptype:'treeviewdragdrop',
      26. appendOnly : true
      27. },
      28. listeners:{
      29. drop:function( node, data, overModel, dropPosition, options){
      30. //ajax的操作把数据同步到后台数据库
      31. alert("把: "+data.records[0].get('text')+" 移动到: "+overModel.get('text'));
      32. },
      33. beforedrop:function( node, data, overModel, dropPosition, dropFunction, options){
      34. // if(overModel.get("leaf")){
      35. // overModel.set('leaf',false)
      36. // }
      37. }
      38. }
      39. },
      40. dockedItems:[{
      41. xtype:'toolbar',
      42. dock:'left',
      43. items:[
      44. {xtype:'button',text:'add',id:'add'},
      45. {xtype:'button',text:'copy',id:'copy'},
      46. {xtype:'button',text:'delete',id:'delete'},
      47. {xtype:'button',text:'paste',id:'paste'}
      48. ]
      49. },{
      50. xtype:'toolbar',
      51. items:[{
      52. xtype:'button',
      53. id:'allopen',
      54. text:'展开全部'
      55. },{
      56. xtype:'button',
      57. id:'allclose',
      58. text:'收起全部'
      59. }]
      60. }],
      61. store:'deptStore'
      62. });

tree+grid 部门管理案例

  • 简单布局应用

    • border布局、tab布局、fit布局
  • 表格的操作
    • 列表的CRUD
    • 控制树形节点的CRUD
  • 树形的操作
    • 自身的一些功能
    • 过滤grid的数据
  • 制作流程
    • 整体框架搭建
    • 表格视图搭建
    • 表格CRUD
    • 树形视图搭建
    • 树形功能实现
    • tree和grid整合
  • 完善
    • 公共函数的抽取
    • 完成保存操作
    • 完成批量删除操作
    • 进一步完善添加操作
    • 解决网友提出后台一个pojo前台就要写一个model的问题(缓存,工厂,Ajax)
    • 树形过滤表格(伪代码和思路)
  • 代码
    • app.js

      1. Ext.onReady(function(){
      2. Ext.QuickTips.init();
      3. Ext.Loader.setConfig({
      4. enabled:true
      5. });
      6. Ext.application({
      7. name : 'AM',
      8. appFolder : "app",
      9. launch:function(){
      10. Ext.create('Ext.container.Viewport', {
      11. padding : "15 15 15 15",
      12. items: {
      13. width: 750,
      14. height: 530,
      15. xtype: 'mainlayout'
      16. }
      17. });
      18. },
      19. controllers:[
      20. 'DeptController'
      21. ]
      22. });
      23. })
    • controller/DeptController.js
      1. /**
      2. * ClassName 部门管理控制器
      3. */
      4. Ext.define("AM.controller.DeptController",{
      5. extend:'Ext.app.Controller',
      6. GridDoActionUtil:Ext.create("AM.util.GridDoActionUtil"),
      7. init: function(){
      8. this.gerGridObj = function(buttion){
      9. return buttion.ownerCt.ownerCt;
      10. };
      11. this.getTreeObj = function(buttion){
      12. return buttion.ownerCt.ownerCt.ownerCt.ownerCt
      13. .child('#west-tree').child("#dept-tree");
      14. };
      15. this.control({
      16. 'depTree':{
      17. itemclick:function(tree,record,item,e,opti){
      18. /**
      19. * 1.得到单击节点的ID
      20. * 2.发到后台重新查询数据load表盒 where id="A0"
      21. * 3.oracle 那就用递归查询
      22. * http://www.uspcat.com/myknowledgebase/oracle/oracl_digui.htm
      23. */
      24. //alert(record.get("id"))
      25. /**
      26. * 1.得到节点ID和子节点的ID
      27. * 2.发到后台重新查询数据load表盒 where id in ("A0","A01010");
      28. */
      29. record.collapse(function(){
      30. return true;
      31. },function(node){
      32. console.log(node);
      33. })
      34. //grid.load({whereSql:'in ('A0')'})
      35. }
      36. },
      37. 'deptlist button[id=delete]':{
      38. click:function(deleteButton){
      39. var grid = this.gerGridObj(deleteButton);
      40. var tree = this.getTreeObj(deleteButton);
      41. this.GridDoActionUtil.doDelete(grid,tree);
      42. }
      43. },
      44. //第二讲中修改
      45. 'deptlist button[id=save]':{
      46. click:function(saveButton){
      47. var grid = this.gerGridObj(saveButton);
      48. var tree = this.getTreeObj(saveButton);
      49. this.GridDoActionUtil.doSave(grid,tree);
      50. }
      51. },
      52. //设定列表添加按钮的事件
      53. 'deptlist button[id=add]':{
      54. click:function(addButton){
      55. //得到数据表格的对象
      56. var grid = this.gerGridObj(addButton);
      57. var modelObj = {
      58. text: '',
      59. id: 'A01',
      60. info :'',
      61. orderIndex:0,
      62. manager:'',
      63. nodeType:'ROOT',
      64. leaf : true
      65. };
      66. //得到tree
      67. var tree = this.getTreeObj(addButton);
      68. this.GridDoActionUtil.doInsert(grid,modelObj,tree);
      69. }
      70. }
      71. })
      72. },
      73. views:[
      74. 'DeptTree',
      75. 'DeptList',
      76. 'MainLayout'
      77. ],
      78. stores:[
      79. 'DeptStore4Tree',
      80. 'DeptStore'
      81. ],
      82. models:[
      83. //'DeptModel'
      84. ]
      85. });
    • model/DeptModel.js(停用)
      1. /**
      2. * ClassName 部门的实体
      3. * text : 部门的名称
      4. * id : id主键
      5. * info : 信息
      6. * orderIndex : 排序字段
      7. * manager : 部门的经理
      8. * nodeType : 节点类型
      9. * leaf : 是否叶子
      10. */
      11. Ext.define("AM.model.DeptModel",{
      12. extend:'Ext.data.Model',
      13. fields:[
      14. {name:'text',type:'string'},
      15. {name:'id',type:'string'},
      16. {name:'info',type:'string'},
      17. {name:'orderIndex',type:'int'},
      18. {name:'manager',type:'string'},
      19. {name:'nodeType',type:'string'},
      20. {name:'leaf',type:'string'}
      21. ]
      22. });
    • store/DeptStore.js
      1. /**
      2. * ClassName 部门实体数据集
      3. */
      4. Ext.define("AM.store.DeptStore",{
      5. extend:'Ext.data.Store',
      6. //model:'AM.model.DeptModel',
      7. model : modelFactory.getModelByName("AM.model.DeptModel"),
      8. proxy:{
      9. api:{
      10. update:'/extjs/extjs!updateDeptList.action',
      11. remove:'/extjs/extjs!updateDeptList.action'
      12. },
      13. type:'ajax',
      14. url:'/extjs/extjs!readDeptForGrid.action',
      15. reader:{
      16. type:'json',
      17. root:'topics'
      18. },
      19. writer:{
      20. type:'json'
      21. }
      22. },
      23. autoLoad:true
      24. });
    • store/DeptStore4Tree.js
      1. Ext.define("AM.store.DeptStore4Tree",{
      2. extend:'Ext.data.TreeStore',
      3. defaultRootId : 'root',
      4. proxy:{
      5. type:'ajax',
      6. url:'/extjs/extjs!readDeptTree.action',
      7. reader:'json'
      8. }
      9. });
    • view/DeptList.js
      1. /**
      2. * ClassName 部门管理数据列表视图
      3. */
      4. Ext.define("AM.view.DeptList",{
      5. extend:'Ext.grid.Panel',
      6. alias:'widget.deptlist',
      7. store:'DeptStore',
      8. width:540,
      9. height:400,
      10. selModel:{
      11. selType:'checkboxmodel'
      12. },
      13. border:0,
      14. multiSelect: true,
      15. frame:true,
      16. tbar:[
      17. {xtype:'button',text:'添加',id:'add',iconCls:'table_add'},
      18. {xtype:'button',text:'删除',id:'delete',iconCls:'table_remove'},
      19. {xtype:'button',text:'保存',id:'save',iconCls:'table_save'}
      20. ],
      21. dockedItems:[{
      22. xtype:'pagingtoolbar',
      23. store:'DeptStore',
      24. dock:'bottom',
      25. displayInfo:true
      26. }],
      27. enableKeyNav:true,
      28. columnLines: true,
      29. columns:[
      30. {text:'部门名称',dataIndex:'text',width:100,
      31. field:{
      32. xtype:'textfield',
      33. allowBlank:false
      34. }
      35. },
      36. {text:'部门经理',dataIndex:'manager',width:100,
      37. field:{
      38. xtype:'textfield',
      39. allowBlank:false
      40. }
      41. },
      42. {text:'顺序排序',dataIndex:'orderIndex',width:100},
      43. {text:'只能简介',dataIndex:'info',width:100}
      44. ],
      45. initComponent:function(){
      46. this.editing = Ext.create("Ext.grid.plugin.CellEditing");
      47. this.plugins = [this.editing];
      48. this.callParent(arguments)
      49. }
      50. });
    • view/DeptTree.js
      1. Ext.define("AM.view.DeptTree",{
      2. extend:'Ext.tree.Panel',
      3. alias:'widget.depTree',
      4. rootVisible:false,//不展示ROOT
      5. displayField:'text',
      6. animate:false,
      7. store:'DeptStore4Tree'
      8. })
    • view/MainLayout.js
      1. Ext.define("AM.view.MainLayout",{
      2. extend:'Ext.panel.Panel',
      3. alias:'widget.mainlayout',
      4. defaults:{
      5. split:true,
      6. bodyStyle:'padding:1px'
      7. },
      8. layout:'border',
      9. items:[{
      10. title:'部门树形',
      11. region:'west',
      12. iconCls:'dept_tree',
      13. xtype:'panel',
      14. margins:'5 2 5 5',
      15. width: 200,
      16. collapsible:true,//可以被折叠
      17. id:'west-tree',
      18. layout:'fit',
      19. items:[{
      20. xtype:'depTree',
      21. id:'dept-tree'
      22. }]
      23. },{
      24. title:'部门数据表格',
      25. iconCls:'dept_table',
      26. region:'center',
      27. xtype:'panel',
      28. id:'center-grid',
      29. margins:'5 5 5 0',
      30. layout:'fit',
      31. items:[{
      32. id:'dept-grid',
      33. xtype:'deptlist'
      34. }]
      35. }]
      36. });
    • comm/ModelFactory.js
      1. /**
      2. * 工厂类
      3. */
      4. Ext.define("AM.model.modelFactory",{
      5. //数据类模型的集合
      6. models:new Ext.util.MixedCollection(),
      7. //字段集合
      8. fields:new Ext.util.MixedCollection(),
      9. getModelByName:function(modelName){
      10. //1.声明类,返回类的ClassName
      11. if(this.models.containsKey(modelName)){
      12. return modelName;
      13. }else{
      14. //ajax拿到我们的字段集合
      15. var fields = [];
      16. if(this.fields.containsKey(modelName)){
      17. fields = this.fields.containsKey(modelName)
      18. }else{
      19. Ext.Ajax.request({
      20. url:'/extjs/extjs!getModelFields.action?modelName='+modelName,
      21. method:'POST',
      22. timeout:4000,
      23. async:false,//跟关键 我不需要异步操作
      24. success:function(response,opts){
      25. fields = eval(response.responseText);
      26. }
      27. });
      28. }
      29. this.fields.add(modelName,fields);
      30. var newModel = Ext.define(modelName,{
      31. extend:'Ext.data.Model',
      32. fields:fields
      33. });
      34. this.models.add(modelName,newModel);
      35. return modelName;
      36. }
      37. }
      38. });
      39. var modelFactory = Ext.create('AM.model.modelFactory',{});
    • util/GridDoActionUtilview.js
      1. Ext.define("AM.util.GridDoActionUtil",{
      2. doDelete:function(grid,treeObj){
      3. if(!grid){
      4. alert("参数传递不正确");
      5. return;
      6. }
      7. //得到数据集合
      8. var store = grid.getStore();
      9. var records = grid.getSelectionModel().getSelection();
      10. var data = [];
      11. Ext.Array.each(records,function(model){
      12. data.push(Ext.JSON.encode(model.get('id')));
      13. });
      14. if(data.length > 0){
      15. Ext.Ajax.request({
      16. url:store.getProxy().api['remove'],
      17. params:{data:"["+data.join(",")+"]"},
      18. method:'POST',
      19. timeout:4000,
      20. success:function(response,opts){
      21. Ext.Array.each(records,function(model){
      22. //tree删除节点
      23. var node = treeObj.getStore().getNodeById(model.get('id'));
      24. var parentNode = node.parentNode;
      25. try{
      26. node.remove(true);
      27. if(parentNode){
      28. if(!parentNode.getChildAt(0)){
      29. parentNode.data['leaf'] = true;
      30. parentNode.updateInfo();
      31. }
      32. }
      33. }catch(e){
      34. console.log(e);
      35. }
      36. //表格删除数据
      37. store.remove(model);
      38. })
      39. }
      40. })
      41. }
      42. },
      43. /**
      44. * 列表的批量修改
      45. * @param {} grid
      46. * @param {} treeObj
      47. */
      48. doSave:function(grid,treeObj){
      49. if(!grid){
      50. alert("参数传递不正确");
      51. return;
      52. }
      53. //得到数据集合
      54. var store = grid.getStore();
      55. //records 被你修改过的数据
      56. var records = store.getUpdatedRecords();
      57. var data = [];
      58. Ext.Array.each(records,function(model){
      59. data.push(Ext.JSON.encode(model.data));
      60. });
      61. //异步的操作数据
      62. // store.getProxy().update(new Ext.data.Operation({
      63. // action:'update'
      64. // }));
      65. if(data.length > 0){
      66. Ext.Ajax.request({
      67. url:store.getProxy().api['update'],
      68. params:{data:"["+data.join(",")+"]"},
      69. method:'POST',
      70. timeout:4000,
      71. success:function(response,opts){
      72. console.log(response.responseText);
      73. Ext.Array.each(records,function(model){
      74. var node = treeObj.getStore().getNodeById(model.get('id'));
      75. node.data['text'] = model.get('text');
      76. node.updateInfo();
      77. //取消小箭头
      78. model.commit();
      79. });
      80. }
      81. });
      82. }
      83. },
      84. /**
      85. * 树形维护表格的插入操作
      86. * @param {} grid
      87. * @param {} modelObj
      88. * @param {} treeObj
      89. */
      90. doInsert:function(grid,modelObj,treeObj){
      91. if(!(grid && modelObj)){
      92. alert("参数传递不正确");
      93. return;
      94. }
      95. //得到表格数据集合
      96. var store = grid.getStore();
      97. //得到目前表格的数据集合长度
      98. var storeCount = store.getCount();
      99. //得到编辑插件
      100. var edit = grid.editing;
      101. //得到数据模型
      102. var model = store.model;
      103. if(storeCount == 0){//证明添加的节点是ROOT
      104. //初始化一个模型的类
      105. var deptObj = new model(modelObj);
      106. edit.cancelEdit();//取消其他插件的编辑活动
      107. store.insert(0,deptObj);
      108. edit.startEditByPosition({
      109. row:0,
      110. column:1
      111. });
      112. if(treeObj){//我们需要树形操作
      113. var rootNode = treeObj.getStore().getRootNode();
      114. rootNode.appendChild({
      115. id:modelObj["id"],
      116. text:modelObj["text"],
      117. leaf:modelObj["leaf"]
      118. });
      119. }
      120. }else{
      121. //得到被选择的数据集合
      122. var checkedRecords = grid.getSelectionModel().getSelection();
      123. if(checkedRecords.length == 1){
      124. var parentRecord = checkedRecords[0];
      125. modelObj['nodeType'] = 'GENERAL';
      126. //第二讲中改********************************
      127. modelObj['id'] = 'A010101';
      128. //得到父节点
      129. var parentNode = treeObj.getStore().getNodeById(parentRecord.get('id'));
      130. try{
      131. parentNode.data['leaf'] = false;
      132. parentNode.updateInfo();
      133. //给它加一个孩子节点
      134. parentNode.appendChild({
      135. id:"A010101",
      136. text:'',
      137. leaf:true
      138. });
      139. parentNode.expand();
      140. }catch(e){
      141. }
      142. edit.cancelEdit();//取消其他插件的编辑活动
      143. var deptObj = new model(modelObj);
      144. store.insert(0,deptObj);
      145. edit.startEditByPosition({
      146. row:0,
      147. column:1
      148. });
      149. }else{
      150. alert("请选择1个父级部门,您现在选择的是["+checkedRecords.length+"]个");
      151. }
      152. }
      153. }
      154. });
    • resources/css/dept.css
      1. .dept_table{
      2. background-image: url(/Learning-extjs4.0/lesson/18/resources/img/dept_table.png) !important;
      3. }
      4. .dept_tree{
      5. background-image: url(/Learning-extjs4.0/lesson/18/resources/img/dept_tree.png) !important;
      6. }
      7. .table_remove{
      8. background-image: url(/Learning-extjs4.0/lesson/18/resources/img/table_remove.gif) !important;
      9. }
      10. .table_add{
      11. background-image: url(/Learning-extjs4.0/lesson/18/resources/img/table_add.png) !important;
      12. }
      13. .table_save{
      14. background-image: url(/Learning-extjs4.0/lesson/18/resources/img/tabel_save.png) !important;
      15. }

form组件

  • 根类 Ext.form.Basic

    • 提供了表单组件,字段管理,数据验证,表单提交,数据加载的功能
  • 表单的容器 Ext.form.Panel
    • 容器自动关联Ext.form.Basic的实例对象更方便的进行字段的配置
    • 重要属性
      • defaultType:”” 设置默认子项 的xtype
  • 数据交互和加载
    • Ext.form.action.Action

      • Ext.form.action.Submit ajax方式提交

        • Ext.form.action.StandardSubmit 原始表单提交方法
      • Ext.form.action.DirectLoad
        • Ext.form.action.DirectSubmit 指令式的模式
  • 字段的控制
    • Ext.form.field.Base 是跟类

      • 混入了类 [Ext.form.field.Field]得到表单值的处理功能
      • 混入了类[Ext.form.Labelable]得到表单标签错误信息提示的功能
      • Ext.form.field.Text 文本框方式的
        • Ext.form.field.TextArea
        • Ext.form.field.Trigger 触发器
          • Ext.form.field.Picker 选择器

            • Ext.form.field.Time
            • Ext.form.field.Date
            • Ext.form.field.Number
            • Ext.form.field.File 文件上传的
            • Ext.form.field.ComboBox 选择框
      • Ext.form.field.Checkbox 选择框方式的
        • Ext.form.field.Radio 单选框
      • Ext.form.field.Hidden 特殊的-隐藏字段
    • Ext.form.field.HtmlEditor 特殊的-文本编辑框
  • 其中夹杂布局的类
    • Ext.form.FieldContainer

      • Ext.form.CheckboxGroup

        • Ext.form.RadioGroup
    • Ext.form.Label
      • Ext.form.Labelable
    • Ext.form.FieldSet
    • Ext.form.FieldContainer
  • 实例讲解
    • Ext.form.Panel

      • 重要的配置项

        • title:’‘,bodyStyle:’‘,frame : ,height: ,width :,
        • renderTo:’‘,defaultType:’‘,defaults:{}
      • 由于混入了Ext.form.Labelable,可以配置
        • labelSeparator 字段名字和值的分割符号、labelWidth 标签宽度
    • Ext.form.field.Text 文本框(xtype: textfield)
      • 重要的配置项

        • width : 150,allowBlank: false, //不能是空
        • labelAlign :’left’,msgTarget:’side’//在字段的右面展示数据
    • Ext.form.field.TextArea
      • getValues()用法
  • 代码
    1. Ext.onReady(function(){
    2. //-------------------------------------
    3. Ext.define("person",{
    4. extend:'Ext.data.Model',
    5. fields:[
    6. {name:'userName',type:'auto'},
    7. {name:'password',type:'auto'}
    8. ]
    9. });
    10. var p = new person({userName:'yunfengcheng2008@126.com',password:"123456"});
    11. //-------------------------------------
    12. var passTest = /[123]/i
    13. Ext.apply(Ext.form.field.VTypes,{
    14. myPass :function(val,field){
    15. return passTest.test(val);
    16. },
    17. myPassText:"密码格式错误",
    18. myPassMask:/[123]/i
    19. });
    20. //-------------------------------------
    21. var textForm = Ext.create("Ext.form.Panel",{
    22. title : "form中文本框实例",
    23. bodyStyle :'padding:5 5 5 5',
    24. frame : true,
    25. height : 120,
    26. width : 300,
    27. id:'my_form',
    28. renderTo:'formDemo',
    29. defaultType:'textfield',
    30. defaults:{
    31. labelSeparator :": ",
    32. labelWidth : 50,
    33. width : 200,
    34. allowBlank: false,
    35. msgTarget : 'side',
    36. labelAlign:'left'
    37. },
    38. items:[{
    39. fieldLabel : "Name",
    40. name:'userName',
    41. id:'userName',
    42. selectOnFocus : true,
    43. regex:/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
    44. regexText:"请用邮箱来注册",
    45. grow:false//是否在这个表单字段规定长度内自动根据文字的内容进行伸缩
    46. },{
    47. fieldLabel : "Pass",
    48. name:'password',
    49. id:'password',
    50. inputType:'password',
    51. vtype:'myPass'
    52. }],
    53. buttons: [
    54. {text:'登陆系统',handler:function(b){
    55. //我没想通过base来得到数值,那我们就要先得到base
    56. //那么base我们有什么办法来的到呢?
    57. //很简单 通过 Ext.form.Basic(findField( String id ) : void)
    58. //那么Ext.form.Basic如何得到呢?
    59. //很简单Ext.form.Panel (getForm( ))
    60. //Ext.form.Panel如何得到呢?
    61. //很简单 1>通过ID来的
    62. var formObj = Ext.getCmp("my_form");
    63. var basic = formObj.getForm();
    64. var nameField = basic.findField("userName");
    65. var nameValue = nameField.getValue();
    66. alert(nameValue);
    67. }},{
    68. text:'重置',handler:function(b){
    69. var formObj = Ext.getCmp("my_form");
    70. var basic = formObj.getForm();
    71. basic.reset();
    72. }
    73. },{
    74. text:'装在数据',handler:function(b){
    75. var formObj = Ext.getCmp("my_form");
    76. var basic = formObj.getForm();
    77. basic.loadRecord(p);
    78. }
    79. }
    80. ]
    81. })
    82. });
    • 数字框
    • CheckBox,radio
    • CheckGroup,RadioGroup
    • Trigger 触发器字段
      • 他指派了一个没有任何动作的接触按钮,需要给他加上不同的动作
  • TextArea.js
    1. Ext.onReady(function(){
    2. var textFomr = Ext.create("Ext.form.Panel",{
    3. title : "form中文本框大文本的实例",
    4. bodyStyle :'padding:5 5 5 5',
    5. frame : true,
    6. height : 250,
    7. width : 400,
    8. id:'my_form',
    9. renderTo:'formDemo',
    10. defaultType:'textfield',
    11. defaults:{
    12. labelSeparator :": ",
    13. labelWidth : 50,
    14. width : 200,
    15. allowBlank: false,
    16. msgTarget : 'side',
    17. labelAlign:'left'
    18. },
    19. items:[{
    20. fieldLabel:'Name',
    21. name:'userName',
    22. id:'userName',
    23. selectOnFocus:true
    24. },{
    25. xtype:'textareafield',
    26. width:300,
    27. height:150,
    28. name:'info',
    29. fieldLabel:'Info'
    30. }],
    31. buttons: [
    32. {text:'登陆系统',handler:function(b){
    33. var formObj = Ext.getCmp("my_form");
    34. var basic = formObj.getForm();
    35. console.log(basic.getValues());
    36. }}]
    37. })
    38. })
  • number.js
    1. Ext.onReady(function(){
    2. var textFomr = Ext.create("Ext.form.Panel",{
    3. title : "form中文本框数字框的实例",
    4. bodyStyle :'padding:5 5 5 5',
    5. frame : true,
    6. height : 250,
    7. width : 400,
    8. id:'my_form',
    9. renderTo:'formDemo',
    10. defaultType:'numberfield',
    11. defaults:{
    12. labelSeparator :": ",
    13. labelWidth : 80,
    14. width : 200,
    15. allowBlank: false,
    16. msgTarget : 'side',
    17. labelAlign:'left'
    18. },
    19. items:[{
    20. fieldLabel:'整数微调',
    21. allowDecimals:false,//叫你不能输入小数
    22. name:'num1',
    23. id:'num1'
    24. },{
    25. fieldLabel:'整数',
    26. allowDecimals:false,//叫你不能输入小数
    27. name:'num2',
    28. id:'num2',
    29. hideTrigger : true
    30. },{
    31. fieldLabel:'小数',
    32. name:'num3',
    33. id:'num3',
    34. emptyText :'请输入小数',
    35. hideTrigger : false,
    36. decimalPrecision:3
    37. },{
    38. fieldLabel:'定界小数',
    39. name:'num3',
    40. id:'num3',
    41. minValue:10,
    42. maxValue:100,
    43. emptyText :'请输入小数',
    44. hideTrigger : false,
    45. decimalPrecision:3
    46. },{
    47. fieldLabel:'输入限定',
    48. name:'num4',
    49. id:'num4',
    50. baseChars:'01',
    51. hideTrigger : true
    52. },{
    53. fieldLabel:'限定步长',
    54. name:'num5',
    55. id:'num5',
    56. step:0.8,
    57. hideTrigger : false,
    58. value:'20'
    59. },{
    60. fieldLabel:'只读字段',
    61. name:'num6',
    62. id:'num6',
    63. step:0.8,
    64. hideTrigger : false,
    65. value:'20',
    66. //readOnly:true
    67. disabled : true
    68. }],
    69. buttons: [
    70. {text:'登陆系统',handler:function(b){
    71. var formObj = Ext.getCmp("my_form");
    72. var basic = formObj.getForm();
    73. console.log(basic.getValues());
    74. }}]
    75. })
    76. })
  • checkbox.js
    1. Ext.onReady(function(){
    2. var textFomr = Ext.create("Ext.form.Panel",{
    3. title : "form中文本框选框的实例",
    4. bodyStyle :'padding:5 5 5 5',
    5. frame : true,
    6. height : 250,
    7. width : 400,
    8. id:'my_form',
    9. renderTo:'formDemo',
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 50,
    13. width : 200,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. xtype:'radiofield',
    20. boxLabel :'男',
    21. inputValue:'m',
    22. fieldLabel:'性别',
    23. checked:true,
    24. name:'sex'
    25. },{
    26. xtype:'radiofield',
    27. boxLabel :'女',
    28. inputValue:'w',
    29. fieldLabel:'性别',
    30. name:'sex'
    31. },{
    32. xtype:'checkboxfield',
    33. inputValue:'1',
    34. name:'hobby',
    35. boxLabel:'唱歌',
    36. fieldLabel:'爱好'
    37. },{
    38. xtype:'checkboxfield',
    39. inputValue:'2',
    40. name:'hobby',
    41. boxLabel:'看书',
    42. fieldLabel:'爱好'
    43. },{
    44. xtype:'checkboxfield',
    45. inputValue:'3',
    46. name:'hobby',
    47. checked:true,
    48. boxLabel:'编程',
    49. fieldLabel:'爱好'
    50. },{
    51. xtype:'checkboxfield',
    52. inputValue:'4',
    53. name:'hobby',
    54. boxLabel:'交友',
    55. fieldLabel:'爱好'
    56. }],
    57. dockedItems:[{
    58. xtype:'toolbar',
    59. dock:'top',
    60. items:[{
    61. text:'选择全部的爱好',
    62. iconCls:'table_comm',
    63. handler:function(){
    64. var formObj = Ext.getCmp("my_form");
    65. var basic = formObj.getForm();
    66. var fields = basic.getFields();
    67. fields.each(function(field){
    68. if("hobby" == field.getName()){
    69. field.setValue(true)
    70. }
    71. })
    72. }
    73. }]
    74. }],
    75. buttons: [
    76. {text:'登陆系统',handler:function(b){
    77. var formObj = Ext.getCmp("my_form");
    78. var basic = formObj.getForm();
    79. console.log(basic.getValues());
    80. }}]
    81. })
    82. })
  • checkboxgroup.js
    1. Ext.onReady(function(){
    2. var textFomr = Ext.create("Ext.form.Panel",{
    3. title : "form中文本框选框的实例",
    4. bodyStyle :'padding:5 5 5 5',
    5. frame : true,
    6. height : 250,
    7. width : 400,
    8. id:'my_form',
    9. renderTo:'formDemo',
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 50,
    13. width : 200,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. xtype:'radiogroup',
    20. fieldLabel:'性别',
    21. columns:2,
    22. items:[{
    23. xtype:'radiofield',
    24. boxLabel :'男',
    25. inputValue:'m',
    26. checked:true,
    27. name:'sex'
    28. },{
    29. xtype:'radiofield',
    30. boxLabel :'女',
    31. inputValue:'w',
    32. name:'sex'
    33. }]
    34. },{
    35. xtype:'checkboxgroup',
    36. fieldLabel:'爱好',
    37. width:335,
    38. columns:4,
    39. items:[{
    40. xtype:'checkboxfield',
    41. inputValue:'1',
    42. name:'hobby',
    43. boxLabel:'唱歌'
    44. },{
    45. xtype:'checkboxfield',
    46. inputValue:'2',
    47. name:'hobby',
    48. boxLabel:'看书'
    49. },{
    50. xtype:'checkboxfield',
    51. inputValue:'3',
    52. name:'hobby',
    53. checked:true,
    54. boxLabel:'编程'
    55. },{
    56. xtype:'checkboxfield',
    57. inputValue:'4',
    58. name:'hobby',
    59. boxLabel:'交友'
    60. }]
    61. }],
    62. dockedItems:[{
    63. xtype:'toolbar',
    64. dock:'top',
    65. items:[{
    66. text:'选择全部的爱好',
    67. iconCls:'table_comm',
    68. handler:function(){
    69. var formObj = Ext.getCmp("my_form");
    70. var basic = formObj.getForm();
    71. var fields = basic.getFields();
    72. fields.each(function(field){
    73. if("hobby" == field.getName()){
    74. field.setValue(true)
    75. }
    76. })
    77. }
    78. }]
    79. }],
    80. buttons: [
    81. {text:'登陆系统',handler:function(b){
    82. var formObj = Ext.getCmp("my_form");
    83. var basic = formObj.getForm();
    84. console.log(basic.getValues());
    85. }}]
    86. })
    87. })
  • Trigger.js
    1. Ext.onReady(function(){
    2. var textFomr = Ext.create("Ext.form.Panel",{
    3. title : "form中文本框触发器的实例",
    4. bodyStyle :'padding:5 5 5 5',
    5. frame : true,
    6. height : 250,
    7. width : 400,
    8. id:'my_form',
    9. renderTo:'formDemo',
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 50,
    13. width : 200,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. xtype:'triggerfield',
    20. fieldLabel:'Name',
    21. name:'userName',
    22. id:'userName',
    23. onTriggerClick:function(e){
    24. var formObj = Ext.getCmp("my_form");
    25. var basic = formObj.getForm();
    26. console.log(basic.getValues());
    27. }
    28. }]
    29. })
    30. })
    • comboBox组件

      • Ext.form.field.ComboBox
      • Ext.view.BoundList 约束列表
      • 本地下拉框
      • Time
      • Date
  • combobox.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. //部门类
    4. Ext.define("department",{
    5. extend:'Ext.data.Model',
    6. fields:[
    7. {name:'name'},
    8. {name:'id'}
    9. ]
    10. });
    11. var st = Ext.create("Ext.data.Store",{
    12. model:'department',
    13. data:[
    14. {name:'销售部',id:'001'},
    15. {name:'人事部',id:'002'},
    16. {name:'研发部',id:'003'},
    17. {name:'产品部',id:'004'},
    18. {name:'实施部',id:'0`05'},
    19. {name:'法务部',id:'006'}
    20. ]
    21. });
    22. Ext.create("Ext.form.Panel",{
    23. title:'本地combobox实例',
    24. renderTo:'formDemo',
    25. bodyPadding:'5 5 5 5',
    26. height:100,
    27. width:270,
    28. frame:true,
    29. defaults:{
    30. labelSeparator :": ",
    31. labelWidth : 70,
    32. width : 200,
    33. allowBlank: false,
    34. msgTarget : 'side',
    35. labelAlign:'left'
    36. },
    37. items:[{
    38. xtype:'combobox',
    39. listConfig:{//控制下拉列表的样式
    40. emptyText:'没有找到匹配的数值',
    41. maxHeight:200
    42. },
    43. fieldLabel:'选择部门',
    44. name:'post',
    45. queryMode:'local',//[local|remot]
    46. store:st,
    47. valueField:"id",
    48. displayField :'name',
    49. forceSelection:true,//不运行使用数据集合中没有的数值
    50. typeAhead : true,
    51. value:'001'
    52. }]
    53. });
    54. });
  • date.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地combobox实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:270,
    9. frame:true,
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 70,
    13. width : 200,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. xtype:'datefield',
    20. fieldLabel:'工作日',
    21. minValue:'01/01/2011',
    22. maxValue:'31/12/2011',
    23. disabledDays :[0,6],
    24. disabledDates:['11年11月08日'],
    25. disabledDatesText:'这个日期你不能选择'
    26. }]
    27. });
    28. });
  • synccombobox.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. //部门类
    4. Ext.define("department",{
    5. extend:'Ext.data.Model',
    6. fields:[
    7. {name:'name'},
    8. {name:'id'},
    9. {name:'c'}
    10. ]
    11. });
    12. var st = Ext.create("Ext.data.Store",{
    13. model:'department',
    14. pageSize:4,
    15. proxy:{
    16. type:'ajax',
    17. url:'/extjs/extjs!getComboBox.action'
    18. }
    19. });
    20. Ext.create("Ext.form.Panel",{
    21. title:'本地combobox实例',
    22. renderTo:'formDemo',
    23. bodyPadding:'5 5 5 5',
    24. height:100,
    25. width:470,
    26. frame:true,
    27. defaults:{
    28. labelSeparator :": ",
    29. labelWidth : 70,
    30. width : 300,
    31. allowBlank: false,
    32. msgTarget : 'side',
    33. labelAlign:'left',
    34. pageSize:4
    35. },
    36. items:[{
    37. xtype:'combobox',
    38. listConfig:{//控制下拉列表的样式
    39. emptyText:'没有找到匹配的数值',
    40. maxHeight:200,
    41. getInnerTpl :function(){
    42. return "<div class='{c}'>{name}.{id}</div>";
    43. }
    44. },
    45. fieldLabel:'城市',
    46. name:'post',
    47. queryMode:'remot',//[local|remot]
    48. store:st,
    49. valueField:"id",
    50. minChars:1,
    51. triggerAction :'all',
    52. queryDelay : 400,
    53. queryParam:'whereSql',
    54. multiSelect:true,//允许多选
    55. displayField :'name'//,
    56. //forceSelection:true,//不运行使用数据集合中没有的数值
    57. //typeAhead : true,
    58. //value:'001'
    59. }]
    60. });
    61. });
  • time.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地combobox实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:270,
    9. frame:true,
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 70,
    13. width : 200,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. xtype:'timefield',
    20. fieldLabel:'上班时间',
    21. minValue:'9:00',
    22. maxValue:'18:00',
    23. minText:'时间要大于{0}',
    24. maxText:'时间要小于{0}',
    25. format:'G时',
    26. increment:60,
    27. invalidText:'时间格式错误',
    28. pickerMaxHeight :100
    29. }]
    30. });
    31. });
    • Ext.form.field.Hidden
    • Ext.form.field.HtmlEditor
    • Ext.form.field.Display 就是为了展示的字段
    • Ext.form.Label
    • Ext.form.FieldSet
    • Ext.form.FieldContainer
    • Ext.form.field.File
  • FieldContainer.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地FieldContainer实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:570,
    9. defaults:{
    10. msgTarget : 'side',
    11. labelAlign:'left'
    12. },
    13. frame:true,
    14. items: [{
    15. xtype: 'fieldcontainer',
    16. fieldLabel: '人员信息',
    17. combineErrors : true,//是否合并展示错误信息
    18. combineLabels: true,//合并展示标签的信息,配合其他使用
    19. labelConnector :',',
    20. layout: {
    21. type:'hbox',//横排布局(这个起了关键性在作用)
    22. align:'middle'//垂直居中
    23. },
    24. fieldDefaults:{
    25. hideLabel:true,//以藏label
    26. allowBlank:false//不允许是空
    27. },
    28. defaultType:'textfield',
    29. items: [{
    30. xtype:'label',
    31. forId:'name',
    32. text:'姓名'
    33. },{
    34. fieldLabel: 'name',//虽然被隐藏但是很有用(展示错误信息)
    35. name: 'name',
    36. inputId:'name'
    37. },{
    38. xtype:'label',
    39. forId:'photo',
    40. text:'电话'
    41. },{xtype: 'displayfield', value: ' ( '},{
    42. name: 'photo',
    43. fieldLabel: 'photo',
    44. inputId:'photo'
    45. },{xtype: 'displayfield', value: ' ) '}]
    46. }],
    47. buttons: [{
    48. text: '提交',
    49. handler: function() {
    50. //up的源码讲解
    51. this.up('form').getForm().submit({
    52. params: {
    53. info: 'age是隐藏字段'
    54. }
    55. });
    56. }
    57. }]
    58. });
    59. });
  • cosupload.jsp
    1. <%@ page language="java" contentType="text/html; charset=GBk"
    2. pageEncoding="GBK"%>
    3. <%@ page import="java.util.*" %>
    4. <%@ page import="java.io.*" %>
    5. <%@ page import="com.hd.util.RandomFileRenamePolicy" %>
    6. <%@page import="com.oreilly.servlet.*"%>
    7. <%
    8. //----------------------------------------
    9. //----------------------------------------
    10. String root = request.getSession().getServletContext().getRealPath("/");
    11. String savePath = root + "file-library\\";
    12. int maxPostSize = 3 * 5 * 1024 * 1024;
    13. RandomFileRenamePolicy frp = new RandomFileRenamePolicy();
    14. MultipartRequest multi = new MultipartRequest(request, savePath, maxPostSize, "utf-8",frp);
    15. String fieldIds = "";
    16. //取得所有已上传文件的名字,返回枚举类型。
    17. Enumeration filesName = multi.getFileNames();
    18. //遍历返回的枚举类型,COS可以上传多个文件,当表单中有多个文本域标签时,使用while关键字遍历.
    19. long l = 0L;
    20. String fileType = null;
    21. String fileName = null;
    22. while(filesName.hasMoreElements()){
    23. //当发现枚举类型中包含文件对象,获取文件对象在枚举中的名字
    24. String fname = (String)filesName.nextElement();
    25. //通过名字获取文件,返回java文件对象
    26. File file = multi.getFile(fname);
    27. //判断是否获得到文件
    28. if(file != null){
    29. //获取文件的真实名字(以便能存储到数据库中)
    30. fileName = multi.getFilesystemName(fname);
    31. fileType = fileName.substring(fileName.lastIndexOf(".")+1);
    32. RandomAccessFile raFile = new RandomAccessFile(new File(savePath+fileType+"\\"+fileName),"r");
    33. l = raFile.length();
    34. fieldIds = fieldIds + fileName+",";
    35. }
    36. }
    37. fieldIds = fieldIds.substring(0,fieldIds.length()-1);
    38. response.setContentType("text/html;charset=GBK");
    39. response.getWriter().print("{'address':'"+RandomFileRenamePolicy.fp+"','docName':'"+RandomFileRenamePolicy.fn+"','fileType':'"+fileType+"','docCode':'"+fileName+"','size':'"+l+"','success':true,'message':'上传成功','ids':'"+fieldIds+"'}");
    40. %>
  • Display.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地Display实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:270,
    9. frame:true,
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 70,
    13. width : 200,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. xtype:'displayfield',
    20. name:'name',
    21. value:'uspcat.com',
    22. fieldLabel:'展示'
    23. }],
    24. buttons:[{
    25. text:'提交',
    26. handler:function(){
    27. this.up("form").getForm().submit({
    28. params:{
    29. info:'age是隐藏字段'
    30. }
    31. });
    32. }
    33. }]
    34. });
    35. })
  • FieldContainer.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地FieldContainer实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:500,
    9. frame:true,
    10. defaults:{
    11. msgTarget:'side',
    12. labelAlign:'left'
    13. },
    14. items:[{
    15. xtype:'fieldcontainer',
    16. layout:{
    17. type:'hbox',
    18. align:'middle'
    19. },
    20. combineLabels:true,
    21. combineErrors:true,
    22. fieldDefaults:{
    23. hideLabel:true,//默认字段会隐藏lebel
    24. allowBlank:false
    25. },
    26. defaultType:'textfield',
    27. items:[{
    28. xtype:'label',
    29. forId:'name',
    30. text:'姓名'
    31. },{
    32. fieldLabel:'name',
    33. name:'name',
    34. inputId:'name'
    35. },{
    36. xtype:'label',
    37. forId:'phone',
    38. text:'电话'
    39. },{
    40. fieldLabel:'phone',
    41. name:'phone',
    42. inputId:'phone'
    43. }]
    44. }],
    45. buttons:[{
    46. text:'提交',
    47. handler:function(){
    48. this.up("form").getForm().submit({
    49. params:{
    50. info:'age是隐藏字段'
    51. }
    52. });
    53. }
    54. }]
    55. });
    56. })
  • FieldSet.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地FieldSet实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:300,
    8. width:270,
    9. frame:true,
    10. items:[{
    11. title:'组合',
    12. xtype:'fieldset',
    13. collapsible:true,//可以展示伸缩的按钮
    14. defaultType:'textfield',
    15. defaults:{
    16. anchor:'95%'
    17. },
    18. layout:'anchor',
    19. items:[{
    20. fieldLabel:'Name',
    21. name:'name'
    22. },{
    23. fieldLabel:'Email',
    24. name:'Email'
    25. }]
    26. },{
    27. title:'组合2',
    28. xtype:'fieldset',
    29. checkboxToggle:true,//启用复选框
    30. collapsible:true,//可以展示伸缩的按钮
    31. defaultType:'textfield',
    32. collapsed:true,//true默认set是收起的
    33. defaults:{
    34. anchor:'95%'
    35. },
    36. layout:'anchor',
    37. items:[{
    38. fieldLabel:'PASS',
    39. name:'PASS'
    40. },{
    41. fieldLabel:'INFO',
    42. name:'INFO'
    43. }]
    44. }],
    45. buttons:[{
    46. text:'提交',
    47. handler:function(){
    48. this.up("form").getForm().submit({
    49. params:{
    50. info:'age是隐藏字段'
    51. }
    52. });
    53. }
    54. }]
    55. });
    56. })
  • File.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地File实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:270,
    9. frame:true,
    10. items:[{
    11. xtype:'filefield',
    12. name:'photo',
    13. fieldLabel:'照片',
    14. labelWidth:50,
    15. msgTarget:'side',
    16. allowBlank:false,
    17. anchor:'98%',
    18. buttonText:'请选中文件'
    19. }],
    20. buttons:[{
    21. text:'提交',
    22. handler:function(){
    23. this.up("form").getForm().submit({
    24. url:'/platform/assistJsp/upload/cosupload.jsp',
    25. waitMsg:'文件上传中',
    26. success:function(){
    27. Ext.Msg.alert("success","文件上传成功");
    28. }
    29. });
    30. }
    31. }]
    32. });
    33. })
  • hidden.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地hiddenfield实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:270,
    9. frame:true,
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 70,
    13. width : 200,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. xtype:'textfield',
    20. name:'name',
    21. fieldLabel:'name',
    22. value:'USPCAT.COM'
    23. },{
    24. xtype:'hiddenfield',
    25. name:'age',
    26. value:'1'
    27. }],
    28. buttons:[{
    29. text:'提交',
    30. handler:function(){
    31. this.up("form").getForm().submit({
    32. params:{
    33. info:'age是隐藏字段'
    34. }
    35. });
    36. }
    37. }]
    38. });
    39. })
  • HtmlEditor.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地htmleditor实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:400,
    8. width:600,
    9. frame:true,
    10. items:[{
    11. xtype:'htmleditor',
    12. name:'HTML',
    13. height:320,
    14. width:580,
    15. fontFamilies :['宋体','黑体','楷体'],
    16. defaultLinkValue :'http://www.uspcat.com'
    17. }],
    18. buttons:[{
    19. text:'提交',
    20. handler:function(){
    21. this.up("form").getForm().submit({
    22. params:{
    23. info:'age是隐藏字段'
    24. }
    25. });
    26. }
    27. }]
    28. });
    29. })
  • Label.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地Label实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:100,
    8. width:270,
    9. frame:true,
    10. items:[{
    11. xtype:'label',
    12. name:'name',
    13. text:'展示',
    14. forId :'myname',
    15. overCls:'a'
    16. },{
    17. xtype:'textfield',
    18. name:'age',
    19. value:'1',
    20. inputId:'myname',
    21. hideLabel:true
    22. }]
    23. });
    24. })
    • 从Grid中装载数据 basic.loadRecord(Model);
    • 服务器装载数据
      • 异步装载
    • 表单的提交操作
      • Ajax提交数据
      • 传统方式提交
  • load.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create("Ext.form.Panel",{
    4. title:'本地load实例',
    5. renderTo:'formDemo',
    6. bodyPadding:'5 5 5 5',
    7. height:300,
    8. width:400,
    9. frame:true,
    10. defaults:{
    11. labelSeparator :": ",
    12. labelWidth : 70,
    13. width : 300,
    14. allowBlank: false,
    15. msgTarget : 'side',
    16. labelAlign:'left'
    17. },
    18. items:[{
    19. fieldLabel:'ID',
    20. xtype:'textfield',
    21. name:'userId',
    22. value:'001'//硬编码写值
    23. },{
    24. fieldLabel:'NAME',
    25. xtype:'textfield',
    26. name:'userName',
    27. value:'uspcat.com'//硬编码写值
    28. },{
    29. fieldLabel:'AGE',
    30. xtype:'numberfield',
    31. name:'userAge',
    32. value:'1'//硬编码写值
    33. },{
    34. xtype:'textareafield',
    35. width:300,
    36. height:150,
    37. name:'info',
    38. fieldLabel:'INFO'
    39. }],
    40. buttons:[{
    41. text:'提交数据',
    42. handler:function(){
    43. //得到form
    44. var basic = this.up("form").getForm();
    45. basic.submit({
    46. clientValidation: true,//要经过客户端验证的
    47. url: '/extjs/extjs!getFormValues.action',
    48. method:'POST',
    49. success:function(){
    50. Ext.Msg.alert('提示',"提交数据");
    51. }
    52. });
    53. }
    54. },{
    55. text:'加载远程数据',
    56. handler:function(){
    57. //得到form
    58. var basic = this.up("form").getForm();
    59. //得到userId
    60. var userId = basic.findField("userId").getValue();
    61. basic.load({
    62. params:{userId:userId},
    63. url:'/extjs/extjs!getFormValues.action',
    64. method:'POST',
    65. success:function(form,action){
    66. Ext.Msg.alert('提示',"加载成功");
    67. },
    68. failure:function(form,action){
    69. Ext.Msg.alert('提示',"失败原因是: "+action.result.errorMessage);
    70. }
    71. });
    72. }
    73. }]
    74. });
    75. });

panel与layout

  • 面板

    • 类结构

      • Ext.Base

        • Ext.AbstractComponent

          • Ext.Component

            • Ext.container.AbstractContainer

              • Ext.container.Container

                • Ext.panel.AbstractPanel

                  • Ext.panel.Panel (是以前版本的Ext.Panel类)
    • 常见的子类
      • Ext.window.Window 控制窗口
      • Ext.form.Panel 控制form
      • Ext.panel.Table 控制grid
      • Ext.tab.Panel 控制工具条
      • Ext.menu.Menu 控制菜单
      • Ext.tip.Tip
      • Ext.container.ButtonGroup
    • 组成面板的部件
      • 底部工具栏,顶部工具栏,面板头部,面板底部,面板体
  • 布局
    • Auto自动布局[Ext.layout.container.Auto]

      • 组件没有指定任何布局方式的时候Auto布局就是默认的布局方式
      • 他采用最原始的HTML流式排版的布局方式
    • Fit自适应布局[Ext.layout.container.Fit]
      • 他是他的(第一个也是唯一个)子元素填满自身的body
    • Accordion折叠(手风琴)布局[Ext.layout.container.Accordion]
      • 他是初始化多个版面,当一个版面处于打开状态下,其他版面就会处于收起状态
    • Card卡片布局[Ext.layout.container.Card]
      • 和折叠布局不同之处在于他是自定义按钮来切换
    • Anchor锚点布局[Ext.layout.container.Anchor]
      • 根据容器的大小为其子元素进行的布局和定位

        • 百分比
        • 偏移量
        • 参考边
    • Absolute绝对定位[Ext.layout.container.Absolute]
    • 多选框布局Ext.layout.container.CheckboxGroup
    • Column列布局[Ext.layout.container.Column]
      • 列风格布局,每一列的宽度可以根据百分比或者固定数值来控制
    • Table表格布局[Ext.layout.container.Table]
      • 和传统的HTML布局方式一样的布局使用方法
    • Border边界布局[Ext.layout.container.Border]
      • 可以控制上,下,左,右,中
    • 盒布局
      • Ext.layout.container.Box
      • Ext.layout.container.VBox 竖排(竖直盒)
      • Ext.layout.container.HBox 横排(水平盒)
      • 主要参数
        • Box

          • flex 具有配置flex的子项,会根据占有总量的比之来决定自己的大小
          • pack 控制子元素展示位置[start左面(这时候flex生效),center(中间),end(右面)]
          • padding 边距
        • HBox
          • align[top,middle,stretch,stretchmax]
        • VBox
          • align[left,center,stretch,stretchmax]
    • Ext.tab.Panel
      • 选项卡布局
      • 特殊(他不在布局的包下面)
  • panel.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.panel.Panel',{
    4. title: '[01]面板的头部[Ext.panel.Header]',
    5. width: 500,
    6. bodyPadding : 10,//边距
    7. height: 400,
    8. hideCollapseTool:false,
    9. collapsible :true,
    10. //animCollapse : false,//控制动画
    11. //frame : true,//渲染面板
    12. autoLoad:'/Learning-extjs4.0/lesson/26/ass.html',//只要是不是null自动加载内容
    13. html: '<p>[02]面板体</p>',//和上面的属性是冲突的
    14. autoScroll:true,//自动滚动条
    15. closable:true,//运行客户关闭
    16. closeAction:'destroy',//设置关闭动作[destroy|hide]
    17. bodyStyle: {
    18. background: '#ffc'
    19. },
    20. renderTo: 'demo',
    21. tbar: [
    22. { xtype: 'button', text: '[03]顶部工具栏' }
    23. ],
    24. bbar: [
    25. { xtype: 'button', text: '[04]底部工具栏 ' }
    26. ],
    27. dockedItems: [{
    28. xtype: 'toolbar',
    29. dock: 'bottom',
    30. ui: 'footer',
    31. items: [
    32. { xtype: 'component', flex: 1 },
    33. { xtype: 'button', text: '[05]面板底部',
    34. handler:function(b){
    35. b.up("panel").removeAll(true)//自动销毁
    36. }
    37. }
    38. ]
    39. }],
    40. tools:[{
    41. type:'refresh',
    42. qtip: '刷新'
    43. },{
    44. type:'help',
    45. qtip: '帮助'
    46. },{
    47. id:'next',
    48. handler: function(event, toolEl, panel){
    49. panel.up("panel").insert(0,{
    50. xtype:'panel',
    51. width:100,
    52. height:100,
    53. bodyStyle: {
    54. background: 'red'
    55. }
    56. })
    57. }
    58. }]
    59. });
    60. });
    61. /**
    62. close、collapse、down、expand、gear、help、left、maximize、minimize
    63. minus、move、next、pin、plus、prev、print、refresh、resize、restore
    64. right、save、search、toggle、unpin、up
    65. */
  • auto.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.Panel', {
    4. width: 800,
    5. height: 280,
    6. title: "AutoLayout布局的面板",
    7. layout: 'auto',//设置布局
    8. renderTo: 'demo',
    9. items: [{
    10. xtype: 'panel',
    11. title: '第一个面板',
    12. width: '75%', //站总体宽度的75%
    13. height: 90
    14. },{
    15. xtype: 'panel',
    16. title: '第二个面板',
    17. width: '75%',
    18. height: 90
    19. },{
    20. xtype: 'panel',
    21. title: '第三个面板',
    22. width: '99%',
    23. height: 90
    24. }]
    25. });
    26. })
  • fit.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.Panel', {
    4. width: 500,
    5. height: 280,
    6. title: "AutoLayout布局的面板",
    7. layout: 'fit',//设置布局
    8. renderTo: 'demo',
    9. items: [{
    10. xtype: 'panel',
    11. title: '第一个面板'
    12. },{
    13. xtype: 'panel',
    14. title: '第二个面板'
    15. }]
    16. });
    17. })
  • Accordion.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.panel.Panel', {
    4. title: 'Accordion布局',
    5. width: 300,
    6. height: 300,
    7. layout:'accordion',
    8. defaults: {
    9. bodyStyle: 'padding:15px'
    10. },
    11. layoutConfig: {
    12. titleCollapse: false,
    13. animate: true,
    14. activeOnTop: true
    15. },
    16. items: [{
    17. title: 'Panel 1',
    18. html: '面板1'
    19. },{
    20. title: 'Panel 2',
    21. html: '面板2'
    22. },{
    23. title: 'Panel 3',
    24. html: '面板3'
    25. }],
    26. renderTo: 'demo'
    27. });
    28. });
  • card.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. var navigate = function(panel, direction,btn){
    4. var layout = panel.getLayout();
    5. layout[direction]();
    6. //next(),prev()
    7. //card的关键函数next( ) : Ext.Component,prev( ) : Ext.Component
    8. //getNext( ) : Ext.Component,getPrev( ) : Ext.Component
    9. Ext.getCmp('move-prev').setDisabled(!layout.getPrev());
    10. Ext.getCmp('move-next').setDisabled(!layout.getNext());
    11. };
    12. Ext.create('Ext.Panel', {
    13. width: 500,
    14. height: 280,
    15. layout: 'card',//设置布局
    16. activeItem:0,//默认展示的子节点索引
    17. renderTo: 'demo',
    18. items: [{
    19. id: 'card-0',
    20. xtype: 'panel',
    21. title: '第一个面板',
    22. html:'第一个面板'
    23. },{
    24. id: 'card-1',
    25. xtype: 'panel',
    26. title: '第二个面板',
    27. html:'第二个面板'
    28. },{
    29. id: 'card-3',
    30. xtype: 'panel',
    31. title: '第三个面板',
    32. html:'第三个面板'
    33. }],
    34. index:1,//自定义索引
    35. titleInfo: "cardt布局的面板",
    36. listeners: {
    37. render:function(){
    38. var panel = this;
    39. panel.setTitle(panel.titleInfo+"("+(this.activeItem+1)+"/"+panel.items.length+")");
    40. }
    41. },
    42. bbar: [{
    43. id: 'move-prev',
    44. text: '上一页',
    45. handler: function(btn) {
    46. var panel = btn.up("panel");
    47. panel.index = panel.index-1;
    48. panel.setTitle(panel.titleInfo+"("+panel.index+"/"+panel.items.length+")");
    49. navigate(panel, "prev");
    50. },
    51. disabled: true
    52. },
    53. '->',
    54. {
    55. id: 'move-next',
    56. text: '下一页',
    57. handler: function(btn) {
    58. var panel = btn.up("panel");
    59. panel.index = panel.index+1;
    60. panel.setTitle(panel.titleInfo+"("+panel.index+"/"+panel.items.length+")");
    61. navigate(panel, "next");
    62. }
    63. }
    64. ]
    65. });
    66. })
  • anchor.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.Panel', {
    4. width: 500,
    5. height: 500,
    6. title: "Anchor布局的面板",
    7. layout: 'anchor',//设置布局
    8. renderTo: 'demo',
    9. items: [{
    10. xtype: 'panel',
    11. title: '75% 宽 and 20% 高',
    12. anchor: '75% 20%'
    13. },{
    14. xtype: 'panel',
    15. title: '偏移量 -300 宽 & -200 高',
    16. anchor: '-300 -200'
    17. },{
    18. xtype: 'panel',
    19. title: '综合使用 -250 宽 20% 高',
    20. anchor: '-250 20%'
    21. }]
    22. });
    23. })
  • Absolute.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.Panel', {
    4. width: 200,
    5. height: 200,
    6. title: "absolute布局的面板",
    7. layout: 'absolute',//设置布局
    8. renderTo: 'demo',
    9. items:[{
    10. title: '子面板',
    11. x: 50,
    12. y: 50,
    13. width: 100,
    14. height: 100,
    15. html: '定位在 x:50, y:40'
    16. }]
    17. });
    18. })
  • column.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.Panel', {
    4. width: 1000,
    5. height: 200,
    6. title: "column布局的面板",
    7. layout: 'column',//设置布局
    8. renderTo: 'demo',
    9. items: [{
    10. title: '宽 = (总宽度-250)*25%',
    11. columnWidth: .25,//这个布局特有的写法
    12. html: 'Content'
    13. },{
    14. title: '宽 = (总宽度-250)*75%',
    15. columnWidth: .75,
    16. html: 'Content'
    17. },{
    18. title: '宽 = 250px',
    19. width: 250,
    20. html: 'Content'
    21. }]
    22. });
    23. })
  • Table.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.Panel', {
    4. width: 400,
    5. height: 230,
    6. title: "table布局的面板",
    7. layout: {
    8. type:'table',
    9. columns:4//四列
    10. },//设置布局
    11. defaults:{
    12. width: 100,
    13. height: 100,
    14. frame:true
    15. },
    16. renderTo: 'demo',
    17. items: [{
    18. title: "1",
    19. width:300,//这个布局特有的写法
    20. colspan: 3//跨三列
    21. },{
    22. title: '2',
    23. height:200,
    24. rowspan:2//跨两行
    25. },{
    26. title: '3'
    27. },{
    28. title: '4'
    29. },{
    30. title: '5'
    31. }]
    32. });
    33. })
  • Border.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.container.Viewport', {//一般是这样配合使用的
    4. //width: 1000,
    5. //height: 800,
    6. //renderTo: Ext.getBody(),
    7. title: "table布局的面板",
    8. layout:'border',
    9. defaults: {
    10. collapsible: true,
    11. split: true,
    12. bodyStyle: 'padding:15px'
    13. },
    14. items: [{
    15. title: '上面north',
    16. region: 'north',
    17. height: 100,
    18. cmargins: '5 0 0 0'
    19. },{
    20. title: '下面south',
    21. region: 'south',
    22. height: 150,
    23. minSize: 75,
    24. maxSize: 250,
    25. cmargins: '5 0 0 0'
    26. },{
    27. title: '左面west',
    28. region:'west',
    29. margins: '5 0 0 0',
    30. cmargins: '5 5 0 0',
    31. width: 175,
    32. minSize: 100,
    33. maxSize: 250
    34. },{
    35. title: '中间Content',
    36. collapsible: false,
    37. region:'center',
    38. margins: '5 0 0 0'
    39. },{
    40. title: '右面east',
    41. width: 175,
    42. region:'east',
    43. margins: '5 0 5 5'
    44. }]
    45. });
    46. })
  • Box.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.Panel', {
    4. width: 400,
    5. height: 230,
    6. renderTo: Ext.getBody(),
    7. title: "Vbox布局的面板",
    8. layout: {
    9. type: 'vbox',
    10. align : 'stretch',
    11. pack : 'start'
    12. },
    13. items: [
    14. {html:'panel 1', flex:1},
    15. {html:'panel 2', height:150},
    16. {html:'panel 3', flex:2}
    17. ]
    18. });
    19. })
  • tab.js
    1. Ext.onReady(function(){
    2. Ext.QuickTips.init();
    3. Ext.create('Ext.tab.Panel', {
    4. width: 400,
    5. height: 230,
    6. renderTo: Ext.getBody(),
    7. items: [{
    8. title: '第一个选项卡'
    9. }, {
    10. title: '第二个选项卡'
    11. }],
    12. buttons:[{
    13. text:'增加选项卡',
    14. handler:function(btn){
    15. var panel = btn.up("tabpanel");
    16. var index = panel.items.length+1;
    17. var tabPage = panel.add({
    18. title: '第'+index+'个选项卡',
    19. html:'我新添加的tab',
    20. closable:true
    21. });
    22. panel.setActiveTab(tabPage);//启用激活他
    23. }
    24. }]
    25. });
    26. })

chart

  • 图表分为坐标轴(axes)和图表序列(series)

    • axes 轴

      • 数值轴 Ext.chart.axis.Numeric
      • 时间轴 Ext.chart.axis.Time
      • 分类轴 Ext.chart.axis.Category
      • 仪表轴 Ext.chart.axis.Gauge
    • series 图表序列
      highlight高亮,label标题,tips提示,renderer格式化
      • 折线图 Ext.chart.series.Line
      • 柱形图 Ext.chart.series.Column
      • 饼状图 Ext.chart.series.Pie
      • 条形图 Ext.chart.series.Bar
      • 面积图 Ext.chart.series.Area
      • 雷达图 Ext.chart.series.Radar 略
      • 散点图 Ext.chart.series.Scatter 略
      • 仪表图 Ext.chart.series.Gauge
  • Numeric.js
    1. var dataStore = Ext.create("Ext.data.Store",{
    2. fields:[
    3. 'name','data'
    4. ],
    5. data:[
    6. {name:'0~10岁',data:120},
    7. {name:'11~18岁',data:170},
    8. {name:'19~24岁',data:175}
    9. ]
    10. });
    11. var b1 = Ext.create("Ext.Window",{
    12. width:600,
    13. height:500,
    14. title:'年龄身高分布图',
    15. shadow:false,
    16. maximizable:true,
    17. layout:'fit',
    18. items:[{
    19. xtype:'chart',
    20. style:'background:#fff',//控制背景颜色
    21. animate :true,//运行动画
    22. shadow : true,
    23. theme:"Category1",//皮肤
    24. store:dataStore,
    25. axes:[{
    26. type:'Numeric',
    27. position:'left',//放置到左边
    28. dashSize:5,//引导线的宽度设置
    29. title:'身高分布(CM)',
    30. fields:['data'],//显示的数据索引
    31. majorTickSteps:5,
    32. minorTickSteps:6,
    33. grid:{
    34. odd:{//奇数行
    35. opacity:1,//不透明
    36. 'stroke-width':0.5//表格线宽
    37. },
    38. even:{//偶数行
    39. opacity:1,//不透明
    40. stroke:'#DDD',
    41. 'stroke-width':0.5//表格线宽
    42. }
    43. }
    44. },{
    45. type:'Category',
    46. position:'bottom',
    47. fields:['name'],
    48. title:'年龄段',
    49. grid:true
    50. }],//轴
    51. series:[{
    52. type:'line',
    53. axis:'left',
    54. xField: 'name',
    55. yField: 'data',
    56. highlight:true,
    57. tips:{
    58. trackMouse: true,
    59. width: 140,
    60. height: 28,
    61. renderer: function(storeItem, item) {
    62. this.setTitle(storeItem.get('name') + ': ' +
    63. storeItem.get('data') + 'CM');
    64. }
    65. }
    66. }]//序列
    67. }]
    68. });
  • Column.js
    1. //定义数据集合
    2. var columnStore1 = Ext.create('Ext.data.JsonStore', {
    3. fields: ['name', 'data'],
    4. data: [
    5. {name:"0~10岁",data:20},
    6. {name:"11~18岁",data:60},
    7. {name:"19~24岁",data:30}
    8. ]
    9. });
    10. var b2 = Ext.create('Ext.Window', {
    11. width: 800,
    12. height: 600,
    13. hidden: false,
    14. closeAction:'hide',
    15. maximizable: true,
    16. title: '柱形图展示图表',
    17. layout: 'fit',
    18. tbar: [{
    19. text: '改变数据',
    20. handler: function() {
    21. columnStore1.loadData([
    22. {name:"0~10岁",data:50},
    23. {name:"11~18岁",data:30},
    24. {name:"19~24岁",data:20}
    25. ]);
    26. }
    27. }],
    28. items: {
    29. id: 'chartCmp',
    30. xtype: 'chart',
    31. style: 'background:#fff',
    32. animate: true,
    33. shadow: true,
    34. store: columnStore1,
    35. axes: [{//轴
    36. type: 'Numeric',
    37. position: 'left',
    38. fields: ['data'],
    39. title: '人数',
    40. grid: true,
    41. minimum: 0
    42. }, {
    43. type: 'Category',
    44. position: 'bottom',
    45. fields: ['name'],
    46. title: '年龄段'
    47. }],//序列
    48. series: [{
    49. type: 'column',
    50. axis: 'left',
    51. highlight: true,
    52. tips: {//提示
    53. trackMouse: true,
    54. width: 140,
    55. height: 28,
    56. renderer: function(storeItem,item) {
    57. this.setTitle(storeItem.get('name') + ': '
    58. + storeItem.get('data') + ' 名');
    59. }
    60. },
    61. //格式化
    62. renderer: function(sprite, record, attr, index, store){
    63. var fieldValue = Math.random() * 20 + 10;
    64. var value = (record.get('data') >> 0) % 3;
    65. var color = ['rgb(213, 70, 121)',
    66. 'rgb(44, 153, 201)',
    67. 'rgb(146, 6, 157)',
    68. 'rgb(49, 149, 0)',
    69. 'rgb(249, 153, 0)'][value];
    70. return Ext.apply(attr, {
    71. fill: color
    72. });
    73. } ,
    74. label: { //控制柱形图label
    75. display: 'insideEnd',
    76. 'text-anchor': 'middle',
    77. field: 'data',
    78. renderer: Ext.util.Format.numberRenderer('0'),
    79. orientation: 'vertical',
    80. color: '#333'
    81. },
    82. xField: 'name',
    83. yField: 'data'
    84. }]
    85. }
    86. });
  • line.js
    1. //定义数据集合
    2. var columnStore2 = Ext.create('Ext.data.JsonStore', {
    3. fields: ['name', 'data1','data2','data3','data4'],
    4. data: [
    5. {name:"一月月考",data1:85,data2:76,data3:94,data4:80},
    6. {name:"二月月考",data1:96,data2:72,data3:87,data4:63},
    7. {name:"三月月考",data1:70,data2:66,data3:68,data4:78},
    8. {name:"四月月考",data1:90,data2:78,data3:76,data4:90}
    9. ]
    10. });
    11. var b3 = Ext.create('Ext.Window', {
    12. width: 800,
    13. height: 600,
    14. hidden: false,
    15. maximizable: true,
    16. closeAction:'hide',
    17. title: 'Line Chart',
    18. renderTo: Ext.getBody(),
    19. layout: 'fit',
    20. tbar: [{
    21. text: '产看另外一个人的成绩',
    22. handler: function() {
    23. columnStore2.loadData([
    24. {name:"一月月考",data1:75,data2:86,data3:84,data4:90},
    25. {name:"二月月考",data1:86,data2:62,data3:87,data4:93},
    26. {name:"三月月考",data1:80,data2:96,data3:68,data4:98},
    27. {name:"四月月考",data1:60,data2:98,data3:76,data4:60}
    28. ]);
    29. }
    30. }],
    31. items: {
    32. xtype: 'chart',
    33. style: 'background:#fff',
    34. animate: true,
    35. store: columnStore2,
    36. shadow: true,//阴影
    37. // mask: 'horizontal',//创建遮罩
    38. // listeners: {//配合遮罩用的隐藏
    39. // select: {
    40. // fn: function(me, selection) {
    41. // //me.setZoom(selection);
    42. // me.mask.hide();
    43. // }
    44. // }
    45. // },
    46. theme: 'Category1',
    47. legend: {
    48. position: 'right'
    49. },
    50. axes: [{//轴
    51. type: 'Numeric',
    52. minimum: 0,
    53. position: 'left',
    54. fields: ['data1', 'data2', 'data3', 'data4'],
    55. title: '分数',
    56. minorTickSteps: 1,//内部去也的跨度
    57. grid: {
    58. odd: {
    59. opacity: 1,
    60. fill: '#ddd',
    61. stroke: '#bbb',
    62. 'stroke-width': 0.5
    63. }
    64. }
    65. }, {
    66. type: 'Category',
    67. position: 'bottom',
    68. fields: ['name'],
    69. title: '历次考试'
    70. }],
    71. series: [{//序列1
    72. type: 'line',
    73. highlight: {
    74. size: 7,
    75. radius: 7
    76. },
    77. axis: 'left',
    78. xField: 'name',
    79. yField: 'data1',//展示在图例上的
    80. title :'语文',
    81. markerConfig: {//标记配置
    82. type: 'cross',//交叉
    83. size: 4,
    84. radius: 4,
    85. 'stroke-width': 0
    86. }
    87. },{//序列2
    88. type: 'line',
    89. highlight: {
    90. size: 7,
    91. radius: 7
    92. },
    93. axis: 'left',
    94. xField: 'name',
    95. yField: 'data2',
    96. title :'数学',
    97. markerConfig: {
    98. type: 'cross',
    99. size: 4,
    100. radius: 4,
    101. 'stroke-width': 0
    102. }
    103. }, {
    104. type: 'line',
    105. highlight: {
    106. size: 7,
    107. radius: 7
    108. },
    109. axis: 'left',//位置
    110. smooth: true,
    111. xField: 'name',
    112. yField: 'data3',
    113. title :'英语',
    114. markerConfig: {
    115. type: 'cross',
    116. size: 4,
    117. radius: 4,
    118. 'stroke-width': 0
    119. }
    120. }, {
    121. type: 'line',
    122. highlight: {
    123. size: 7,
    124. radius: 7
    125. },
    126. axis: 'left',
    127. smooth: true,
    128. fill: true,//填充颜色
    129. xField: 'name',
    130. yField: 'data4',
    131. title :'计算机',
    132. markerConfig: {
    133. type: 'circle',//圈
    134. size: 4,
    135. radius: 4,
    136. 'stroke-width': 0
    137. }
    138. }]
    139. }
    140. });
  • Pie.js

    1. var columnStore5 = Ext.create('Ext.data.JsonStore', {
    2. fields: ['name', 'data'],
    3. data: [
    4. {name:"0~10岁",data:20},
    5. {name:"11~18岁",data:60},
    6. {name:"19~24岁",data:30}
    7. ]
    8. });
    9. var b4 = Ext.create('Ext.Window', {
    10. width: 800,
    11. height: 600,
    12. title: '饼图示例',
    13. layout: 'fit',
    14. closeAction:'hide',
    15. tbar: [{
    16. text: '数据变换',
    17. handler: function() {
    18. columnStore5.loadData([
    19. {name:"0~10岁",data:40},
    20. {name:"11~18岁",data:20},
    21. {name:"19~24岁",data:40}
    22. ]);
    23. }
    24. }, {
    25. enableToggle: true,
    26. pressed: false,
    27. text: 'Donut(设置内圆)',
    28. toggleHandler: function(btn, pressed) {
    29. var chart = Ext.getCmp('chartCmp');
    30. //设置图标序列的模式
    31. chart.series.first().donut = pressed ? 35 : false;//内弧度
    32. chart.refresh();
    33. }
    34. }],
    35. items: {
    36. xtype: 'chart',
    37. id: 'chartCmp',
    38. animate: true,
    39. store: columnStore5,
    40. shadow: true,
    41. legend: {
    42. position: 'right'
    43. },
    44. insetPadding: 60,
    45. theme: 'Base:gradients',
    46. series: [{
    47. type: 'pie',
    48. field: 'data',
    49. showInLegend: true,
    50. donut: false,//内环状线圈
    51. tips: {//提示
    52. trackMouse: true,
    53. width: 140,
    54. height: 28,
    55. renderer: function(storeItem, item) {
    56. var total = 0;
    57. columnStore5.each(function(rec) {
    58. total += rec.get('data');
    59. });
    60. this.setTitle(storeItem.get('name') + ': '
    61. + Math.round(storeItem.get('data')/total*100)
    62. + '%');
    63. }
    64. },
    65. highlight: {//高亮
    66. segment: {
    67. margin: 20
    68. }
    69. },
    70. label: {
    71. field: 'name',
    72. display: 'rotate',
    73. contrast: true,
    74. font: '18px Arial'
    75. }
    76. }]
    77. }
    78. });
  • Bar.js
    1. var columnStore6 = Ext.create('Ext.data.JsonStore', {
    2. fields: ['name', 'data'],
    3. data: [
    4. {name:"0~10岁",data:122},
    5. {name:"11~18岁",data:163},
    6. {name:"19~24岁",data:234},
    7. {name:"15~35岁",data:737},
    8. {name:"36~42岁",data:453},
    9. {name:"43~60岁",data:540}
    10. ]
    11. });
    12. var b5 = Ext.create('Ext.Window', {
    13. width: 800,
    14. height: 600,
    15. hidden: false,
    16. maximizable: true,
    17. title: 'Bar Renderer',
    18. renderTo: Ext.getBody(),
    19. layout: 'fit',
    20. tbar: [{
    21. text: '重新装载数据',
    22. handler: function() {
    23. columnStore6.loadData( [
    24. {name:"0~10岁",data:221},
    25. {name:"11~18岁",data:363},
    26. {name:"19~24岁",data:135},
    27. {name:"15~35岁",data:432},
    28. {name:"36~42岁",data:756},
    29. {name:"43~60岁",data:649}
    30. ]);
    31. }
    32. }],
    33. items: {
    34. xtype: 'chart',
    35. animate: true,
    36. style: 'background:#fff',
    37. shadow: false,//阴影
    38. store: columnStore6,
    39. axes: [{
    40. type: 'Numeric',
    41. position: 'bottom',
    42. fields: ['data'],
    43. label: {
    44. renderer: Ext.util.Format.numberRenderer('0,0')
    45. },
    46. title: '人数',
    47. minimum: 0
    48. }, {
    49. type: 'Category',
    50. position: 'left',
    51. fields: ['name'],
    52. title: '年龄分布'
    53. }],
    54. series: [{
    55. type: 'bar',
    56. axis: 'bottom',
    57. label: {
    58. display: 'insideEnd',
    59. field: 'data1',
    60. renderer: Ext.util.Format.numberRenderer('0'),
    61. orientation: 'horizontal',
    62. color: '#333',
    63. 'text-anchor': 'middle',
    64. contrast: true
    65. },
    66. xField: 'name',
    67. yField: ['data'],
    68. renderer: function(sprite, record, attr, index, store) {
    69. var fieldValue = Math.random() * 20 + 10;
    70. var value = (record.get('data') >> 0) % 5;
    71. var color = ['rgb(213, 70, 121)',
    72. 'rgb(44, 153, 201)',
    73. 'rgb(146, 6, 157)',
    74. 'rgb(49, 149, 0)',
    75. 'rgb(249, 153, 0)'][value];
    76. return Ext.apply(attr, {
    77. fill: color
    78. });
    79. }
    80. }]
    81. }
    82. });
  • area.js
    1. //Ext.onReady(function () {
    2. var columnStore7 = Ext.create('Ext.data.JsonStore', {
    3. fields: ['name', 'data1','data2','data3','data4'],
    4. data: [
    5. {name:"一月月考",data1:85,data2:76,data3:94,data4:80},
    6. {name:"二月月考",data1:96,data2:72,data3:87,data4:63},
    7. {name:"三月月考",data1:70,data2:66,data3:68,data4:78},
    8. {name:"四月月考",data1:90,data2:78,data3:76,data4:90}
    9. ]
    10. });
    11. var b6 = Ext.create('Ext.Window', {
    12. width: 800,
    13. height: 600,
    14. hidden: false,
    15. shadow: false,
    16. maximizable: true,
    17. title: 'Area Chart',
    18. renderTo: Ext.getBody(),
    19. layout: 'fit',
    20. tbar: [{
    21. text: '切换数据',
    22. handler: function() {
    23. columnStore7.loadData([
    24. {name:"一月月考",data1:75,data2:86,data3:84,data4:90},
    25. {name:"二月月考",data1:86,data2:62,data3:87,data4:93},
    26. {name:"三月月考",data1:80,data2:96,data3:68,data4:98},
    27. {name:"四月月考",data1:60,data2:98,data3:76,data4:60}
    28. ]);
    29. }
    30. }, {
    31. enableToggle: true,
    32. pressed: true,
    33. text: '动画开启|关闭',
    34. toggleHandler: function(btn, pressed) {
    35. var chart = Ext.getCmp('chartCmp');
    36. chart.animate = pressed?{easing: 'ease', duration: 500 }:false;
    37. }
    38. }],
    39. items: {
    40. id: 'chartCmp',
    41. xtype: 'chart',
    42. style: 'background:#fff',
    43. animate: true,
    44. store: columnStore7,
    45. legend: {
    46. position: 'bottom'
    47. },
    48. axes: [{
    49. type: 'Numeric',
    50. grid: true,
    51. position: 'left',//位置
    52. fields: ['data1', 'data2', 'data3', 'data4'],
    53. title: '分数分布',
    54. grid: {
    55. odd: {
    56. opacity: 1,
    57. fill: '#ddd',
    58. stroke: '#bbb',
    59. 'stroke-width': 1
    60. }
    61. },
    62. minimum: 0,
    63. adjustMinimumByMajorUnit: 0
    64. }, {
    65. type: 'Category',
    66. position: 'bottom',
    67. fields: ['name'],
    68. title: '每月考试',
    69. grid: true,
    70. label: {
    71. rotate: {
    72. degrees: 315
    73. }
    74. }
    75. }],
    76. series: [{
    77. type: 'area',
    78. highlight: false,
    79. axis: 'left',
    80. xField: 'name',
    81. yField: ['data1', 'data2', 'data3', 'data4'],
    82. style: {
    83. opacity: 0.93
    84. }
    85. }]
    86. }
    87. });
    88. //})
  • area.js(加)
    1. Ext.require('Ext.chart.*');
    2. Ext.require('Ext.data.*');
    3. Ext.require('Ext.Window');
    4. Ext.require('Ext.layout.container.Fit');
    5. Ext.require('Ext.fx.target.Sprite');
    6. //规划数据
    7. var jsonData = [
    8. {
    9. date: '1/1/2009',
    10. IE: 44.8,
    11. Firefox: 45.5,
    12. Chrome: 3.9,
    13. Safari: 3,
    14. Opera: 2.3,
    15. Other: 0.5
    16. },
    17. {
    18. date: '2/1/2009',
    19. IE: 43.6,
    20. Firefox: 46.4,
    21. Chrome: 4,
    22. Safari: 3,
    23. Opera: 2.2,
    24. Other: 0.8
    25. },
    26. {
    27. date: '3/1/2009',
    28. IE: 43.3,
    29. Firefox: 46.5,
    30. Chrome: 4.2,
    31. Safari: 3.1,
    32. Opera: 2.3,
    33. Other: 0.6
    34. },
    35. {
    36. date: '4/1/2009',
    37. IE: 42.1,
    38. Firefox: 47.1,
    39. Chrome: 4.9,
    40. Safari: 3,
    41. Opera: 2.2,
    42. Other: 0.7
    43. },
    44. {
    45. date: '5/1/2009',
    46. IE: 41,
    47. Firefox: 47.7,
    48. Chrome: 5.5,
    49. Safari: 3,
    50. Opera: 2.2,
    51. Other: 0.6
    52. },
    53. {
    54. date: '6/1/2009',
    55. IE: 40.7,
    56. Firefox: 47.3,
    57. Chrome: 6,
    58. Safari: 3.1,
    59. Opera: 2.1,
    60. Other: 0.8
    61. },
    62. {
    63. date: '7/1/2009',
    64. IE: 39.4,
    65. Firefox: 47.9,
    66. Chrome: 6.5,
    67. Safari: 3.3,
    68. Opera: 2.1,
    69. Other: 0.8
    70. },
    71. {
    72. date: '8/1/2009',
    73. IE: 39.3,
    74. Firefox: 47.4,
    75. Chrome: 7,
    76. Safari: 3.3,
    77. Opera: 2.1,
    78. Other: 0.9
    79. },
    80. {
    81. date: '9/1/2009',
    82. IE: 39.6,
    83. Firefox: 46.6,
    84. Chrome: 7.1,
    85. Safari: 3.6,
    86. Opera: 2.2,
    87. Other: 0.9
    88. },
    89. {
    90. date: '10/1/2009',
    91. IE: 37.5,
    92. Firefox: 47.5,
    93. Chrome: 8,
    94. Safari: 3.8,
    95. Opera: 2.3,
    96. Other: 0.9
    97. },
    98. {
    99. date: '11/1/2009',
    100. IE: 37.7,
    101. Firefox: 47,
    102. Chrome: 8.5,
    103. Safari: 3.8,
    104. Opera: 2.3,
    105. Other: 0.7
    106. },
    107. {
    108. date: '12/1/2009',
    109. IE: 37.2,
    110. Firefox: 46.4,
    111. Chrome: 9.8,
    112. Safari: 3.6,
    113. Opera: 2.3,
    114. Other: 0.7
    115. },
    116. {
    117. date: '1/1/2010',
    118. IE: 36.2,
    119. Firefox: 46.3,
    120. Chrome: 10.8,
    121. Safari: 3.7,
    122. Opera: 2.2,
    123. Other: 0.8
    124. },
    125. {
    126. date: '2/1/2010',
    127. IE: 35.3,
    128. Firefox: 46.5,
    129. Chrome: 11.6,
    130. Safari: 3.8,
    131. Opera: 2.1,
    132. Other: 0.7
    133. },
    134. {
    135. date: '3/1/2010',
    136. IE: 34.9,
    137. Firefox: 46.2,
    138. Chrome: 12.3,
    139. Safari: 3.7,
    140. Opera: 2.2,
    141. Other: 0.7
    142. },
    143. {
    144. date: '4/1/2010',
    145. IE: 33.4,
    146. Firefox: 46.4,
    147. Chrome: 13.6,
    148. Safari: 3.7,
    149. Opera: 2.2,
    150. Other: 0.7
    151. },
    152. {
    153. date: '5/1/2010',
    154. IE: 32.2,
    155. Firefox: 46.9,
    156. Chrome: 14.5,
    157. Safari: 3.5,
    158. Opera: 2.2,
    159. Other: 0.7
    160. },
    161. {
    162. date: '6/1/2010',
    163. IE: 31,
    164. Firefox: 46.6,
    165. Chrome: 15.9,
    166. Safari: 3.6,
    167. Opera: 2.1,
    168. Other: 0.8
    169. },
    170. {
    171. date: '7/1/2010',
    172. IE: 30.4,
    173. Firefox: 46.4,
    174. Chrome: 16.7,
    175. Safari: 3.4,
    176. Opera: 2.3,
    177. Other: 0.8
    178. },
    179. {
    180. date: '8/1/2010',
    181. IE: 30.7,
    182. Firefox: 45.8,
    183. Chrome: 17,
    184. Safari: 3.5,
    185. Opera: 2.3,
    186. Other: 0.7
    187. },
    188. {
    189. date: '9/1/2010',
    190. IE: 31.1,
    191. Firefox: 45.1,
    192. Chrome: 17.3,
    193. Safari: 3.7,
    194. Opera: 2.2,
    195. Other: 0.6
    196. },
    197. {
    198. date: '10/1/2010',
    199. IE: 29.7,
    200. Firefox: 44.1,
    201. Chrome: 19.2,
    202. Safari: 3.9,
    203. Opera: 2.2,
    204. Other: 0.9
    205. },
    206. {
    207. date: '11/1/2010',
    208. IE: 28.6,
    209. Firefox: 44,
    210. Chrome: 20.5,
    211. Safari: 4.0,
    212. Opera: 2.3,
    213. Other: 0.6
    214. },
    215. {
    216. date: '12/1/2010',
    217. IE: 27.5,
    218. Firefox: 43.5,
    219. Chrome: 22.4,
    220. Safari: 3.8,
    221. Opera: 2.2,
    222. Other: 0.6
    223. }
    224. ];
    225. //数据fields数据抽取
    226. var fields = ['IE', 'Chrome', 'Firefox', 'Safari', 'Opera', 'Other'];
    227. //创建数据
    228. var browserStore = Ext.create('Ext.data.JsonStore', {
    229. fields: fields,
    230. data: jsonData
    231. });
    232. var colors = ['rgb(47, 162, 223)',
    233. 'rgb(60, 133, 46)',
    234. 'rgb(234, 102, 17)',
    235. 'rgb(154, 176, 213)',
    236. 'rgb(186, 10, 25)',
    237. 'rgb(40, 40, 40)'];
    238. //扩展原始类[Ext.chart.theme.Base]属性colors
    239. Ext.chart.theme.Browser = Ext.extend(Ext.chart.theme.Base, {
    240. constructor: function(config) {
    241. Ext.chart.theme.Base.prototype.constructor.call(this, Ext.apply({
    242. colors: colors
    243. }, config));
    244. }
    245. });
    246. var b7 = Ext.create('Ext.Window', {
    247. width: 800,
    248. height: 600,
    249. hidden: false,
    250. shadow: false,
    251. maximizable: false,
    252. title: '浏览器使用分布',
    253. //renderTo: Ext.getBody(),
    254. layout: 'fit',
    255. items: {
    256. id: 'chartCmp',
    257. xtype: 'chart',
    258. style: 'background:#fff',
    259. animate: true,
    260. theme: 'Browser:gradients',//皮肤
    261. defaultInsets: 30,
    262. store: browserStore,//数据引用
    263. legend: {
    264. position: 'right'//图例的设置
    265. },
    266. axes: [{//轴
    267. type: 'Numeric',
    268. position: 'left',
    269. fields: fields,
    270. title: '使用率 %',
    271. grid: true,
    272. decimals: 0,//小数进位数值 默认是2
    273. minimum: 0,//设置最小数值,如果没有设置则按章数据的最小数值自动计算
    274. maximum: 100//设置最大数值,如果没有设置则按照数据的最大数值自动计算
    275. }, {
    276. type: 'Category',//类型轴
    277. position: 'bottom',
    278. fields: ['date'],
    279. title: '2011年月度分布',
    280. label: {
    281. renderer: function(v) {
    282. return v.match(/([0-9]*)\/[0-9]*\/[0-9][0-9]([0-9]*)/).slice(1).join('/');
    283. }
    284. }
    285. }],
    286. series: [{
    287. type: 'area',//面积图
    288. axis: 'left',
    289. highlight: true,//高亮
    290. tips: {//提示
    291. trackMouse: true,
    292. width: 170,
    293. height: 28,
    294. renderer: function(storeItem, item) {
    295. this.setTitle(item.storeField + ' - '
    296. + Ext.Date.format(new Date(storeItem.get('date')), 'M y')
    297. + ' - ' + storeItem.get(item.storeField) + '%');
    298. }
    299. },
    300. xField: 'name',
    301. yField: fields,
    302. style: {
    303. lineWidth: 1,
    304. stroke: '#666',
    305. opacity: 0.86
    306. }
    307. }]
    308. }
    309. });
  • Gauge.js

    1. var s1 = Ext.create('Ext.data.JsonStore', {
    2. fields: ['name', 'data'],
    3. data: [
    4. {name:"0~10岁",data:20}
    5. ]
    6. });
    7. var s2 = Ext.create('Ext.data.JsonStore', {
    8. fields: ['name', 'data'],
    9. data: [
    10. {name:"0~10岁",data:50}
    11. ]
    12. });
    13. var s3 = Ext.create('Ext.data.JsonStore', {
    14. fields: ['name', 'data'],
    15. data: [
    16. {name:"0~10岁",data:30}
    17. ]
    18. });
    19. var b8 = Ext.create('Ext.Window', {
    20. width: 800,
    21. height: 250,
    22. minWidth: 650,
    23. minHeight: 225,
    24. title: 'Gauge Charts',
    25. tbar: [{
    26. text: '装载新的数据',
    27. handler: function() {
    28. s1.loadData([
    29. {name:"0~10岁",data:50}
    30. ]);
    31. s2.loadData([
    32. {name:"0~10岁",data:20}
    33. ]);
    34. s3.loadData([
    35. {name:"0~10岁",data:70}
    36. ]);
    37. }
    38. }],
    39. layout: {
    40. type: 'hbox',
    41. align: 'stretch'
    42. },
    43. items: [{//第一个仪表图
    44. xtype: 'chart',
    45. style: 'background:#fff',
    46. animate: {
    47. easing: 'elasticIn',
    48. duration: 1000
    49. },
    50. store: s1,
    51. insetPadding: 25,
    52. flex: 1,
    53. axes: [{
    54. type: 'gauge',
    55. position: 'gauge',
    56. minimum: 0,
    57. maximum: 100,
    58. steps: 10,
    59. margin: -10
    60. }],
    61. series: [{
    62. type: 'gauge',
    63. field: 'data',
    64. donut: false,
    65. colorSet: ['#F49D10', '#ddd']
    66. }]
    67. }, {//第二个仪表图
    68. xtype: 'chart',
    69. style: 'background:#fff',
    70. animate: true,
    71. store: s2,
    72. insetPadding: 25,
    73. flex: 1,
    74. axes: [{
    75. type: 'gauge',
    76. position: 'gauge',
    77. minimum: 0,
    78. maximum: 100,
    79. steps: 10,
    80. margin: 7
    81. }],
    82. series: [{
    83. type: 'gauge',
    84. field: 'data',
    85. donut: 30,
    86. colorSet: ['#82B525', '#ddd']
    87. }]
    88. }, {//第三个仪表图
    89. xtype: 'chart',
    90. style: 'background:#fff',
    91. animate: {
    92. easing: 'bounceOut',
    93. duration: 500
    94. },
    95. store: s3,
    96. insetPadding: 25,
    97. flex: 1,
    98. axes: [{
    99. type: 'gauge',
    100. position: 'gauge',
    101. minimum: 0,
    102. maximum: 100,
    103. steps: 10,
    104. margin: 7
    105. }],
    106. series: [{
    107. type: 'gauge',
    108. field: 'data',
    109. donut: 80,
    110. colorSet: ['#3AA8CB', '#ddd']
    111. }]
    112. }]
    113. })
  • Radar.js

    1. var columnStore9 = Ext.create('Ext.data.JsonStore', {
    2. fields: ['name', 'data1','data2','data3','data4'],
    3. data: [
    4. {name:"一月月考",data1:85,data2:76,data3:94},
    5. {name:"二月月考",data1:96,data2:72,data3:87},
    6. {name:"三月月考",data1:70,data2:66,data3:68},
    7. {name:"四月月考",data1:50,data2:88,data3:56},
    8. {name:"五月月考",data1:80,data2:88,data3:36},
    9. {name:"六月月考",data1:40,data2:68,data3:96},
    10. {name:"七月月考",data1:60,data2:88,data3:86},
    11. {name:"八月月考",data1:70,data2:88,data3:96},
    12. {name:"九月月考",data1:80,data2:98,data3:66},
    13. {name:"十月月考",data1:90,data2:78,data3:76},
    14. {name:"十一月月考",data1:90,data2:78,data3:76},
    15. {name:"十二月月考",data1:90,data2:78,data3:76}
    16. ]
    17. });
    18. var b9 = Ext.create('Ext.Window', {
    19. width: 800,
    20. height: 600,
    21. hidden: false,
    22. shadow: false,
    23. maximizable: true,
    24. style: 'overflow: hidden;',
    25. title: 'Radar Chart',
    26. renderTo: Ext.getBody(),
    27. layout: 'fit',
    28. tbar: [{
    29. text: '装载数据',
    30. handler: function() {
    31. columnStore9.loadData( [
    32. {name:"一月月考",data1:75,data2:86,data3:74},
    33. {name:"二月月考",data1:96,data2:82,data3:87},
    34. {name:"三月月考",data1:70,data2:96,data3:68},
    35. {name:"四月月考",data1:50,data2:78,data3:56},
    36. {name:"五月月考",data1:90,data2:88,data3:36},
    37. {name:"六月月考",data1:80,data2:68,data3:96},
    38. {name:"七月月考",data1:60,data2:88,data3:86},
    39. {name:"八月月考",data1:70,data2:98,data3:86},
    40. {name:"九月月考",data1:88,data2:98,data3:66},
    41. {name:"十月月考",data1:70,data2:88,data3:96},
    42. {name:"十一月月考",data1:90,data2:78,data3:76},
    43. {name:"十二月月考",data1:90,data2:98,data3:76}
    44. ]);
    45. }
    46. }, {
    47. enableToggle: true,
    48. pressed: true,
    49. text: 'Animate',
    50. toggleHandler: function(btn, pressed) {
    51. var chart = Ext.getCmp('chartCmp');
    52. chart.animate = pressed ? { easing: 'ease', duration: 500 } : false;
    53. }
    54. }],
    55. items: {
    56. id: 'chartCmp',
    57. xtype: 'chart',
    58. style: 'background:#fff',
    59. theme: 'Category2',
    60. animate: true,
    61. store: columnStore9,
    62. insetPadding: 20,
    63. legend: {
    64. position: 'right'//图例
    65. },
    66. axes: [{//轴
    67. type: 'Radial',
    68. position: 'radial',
    69. label: {
    70. display: true
    71. }
    72. }],
    73. series: [{
    74. type: 'radar',
    75. xField: 'name',
    76. yField: 'data1',
    77. showInLegend: true,//展示在图例
    78. showMarkers: true,
    79. markerConfig: {
    80. radius: 5,
    81. size: 5
    82. },
    83. style: {
    84. 'stroke-width': 2,
    85. //fill: 'yellow'//没有填充
    86. fill:'none'
    87. }
    88. },{
    89. type: 'radar',
    90. xField: 'name',
    91. yField: 'data2',
    92. showInLegend: true,
    93. showMarkers: true,
    94. markerConfig: {
    95. radius: 5,
    96. size: 5
    97. },
    98. style: {
    99. 'stroke-width': 2,
    100. fill: 'none'
    101. }
    102. },{
    103. type: 'radar',
    104. xField: 'name',
    105. yField: 'data3',
    106. showMarkers: true,
    107. showInLegend: true,
    108. markerConfig: {
    109. radius: 5,
    110. size: 5
    111. },
    112. style: {
    113. 'stroke-width': 2,
    114. fill: 'none'
    115. }
    116. }]
    117. }
    118. });
  • demo.js
    1. var chart;
    2. var generateData = (function() {
    3. var data = [], i = 0,
    4. last = false,
    5. date = new Date(2011, 1, 1),
    6. seconds = +date,
    7. min = Math.min,
    8. max = Math.max,
    9. random = Math.random;
    10. return function() {
    11. data = data.slice();
    12. data.push({
    13. date: Ext.Date.add(date, Ext.Date.DAY, i++),
    14. visits: min(100, max(last? last.visits + (random() - 0.5) * 20 : random() * 100, 0)),
    15. views: min(100, max(last? last.views + (random() - 0.5) * 10 : random() * 100, 0)),
    16. users: min(100, max(last? last.users + (random() - 0.5) * 20 : random() * 100, 0))
    17. });
    18. last = data[data.length -1];
    19. return data;
    20. };
    21. })();
    22. var group = false,
    23. groupOp = [{
    24. dateFormat: 'M d',
    25. groupBy: 'year,month,day'
    26. }, {
    27. dateFormat: 'M',
    28. groupBy: 'year,month'
    29. }];
    30. function regroup() {
    31. group = !group;
    32. var axis = chart.axes.get(1),
    33. selectedGroup = groupOp[+group];
    34. axis.dateFormat = selectedGroup.dateFormat;
    35. axis.groupBy = selectedGroup.groupBy;
    36. chart.redraw();
    37. }
    38. var store = Ext.create('Ext.data.JsonStore', {
    39. fields: ['date', 'visits', 'views', 'users'],
    40. data: generateData()
    41. });
    42. //关键函数
    43. var intr = setInterval(function() {
    44. var gs = generateData();
    45. var toDate = timeAxis.toDate,
    46. lastDate = gs[gs.length - 1].date,
    47. markerIndex = chart.markerIndex || 0;
    48. if (+toDate < +lastDate) {
    49. markerIndex = 1;
    50. timeAxis.toDate = lastDate;
    51. timeAxis.fromDate = Ext.Date.add(Ext.Date.clone(timeAxis.fromDate), Ext.Date.DAY, 1);
    52. chart.markerIndex = markerIndex;
    53. }
    54. store.loadData(gs);
    55. }, 1000);
    56. var b10 = Ext.create('Ext.Window', {
    57. width: 800,
    58. height: 600,
    59. hidden: false,
    60. maximizable: true,
    61. title: 'Live Animated Chart',
    62. renderTo: Ext.getBody(),
    63. layout: 'fit',
    64. items: [{
    65. xtype: 'chart',
    66. style: 'background:#fff',
    67. id: 'chartCmp',
    68. store: store,
    69. shadow: false,
    70. animate: true,
    71. axes: [{
    72. type: 'Numeric',
    73. grid: true,
    74. minimum: 0,
    75. maximum: 100,
    76. position: 'left',
    77. fields: ['views', 'visits', 'users'],
    78. title: 'Number of Hits',
    79. grid: {
    80. odd: {
    81. fill: '#dedede',
    82. stroke: '#ddd',
    83. 'stroke-width': 0.5
    84. }
    85. }
    86. }, {
    87. type: 'Time',
    88. position: 'bottom',
    89. fields: 'date',
    90. title: 'Day',
    91. dateFormat: 'M d',
    92. groupBy: 'year,month,day',
    93. aggregateOp: 'sum',
    94. constrain: true,
    95. fromDate: new Date(2011, 1, 1),
    96. toDate: new Date(2011, 1, 7),
    97. grid: true
    98. }],
    99. series: [{
    100. type: 'line',
    101. smooth: false,
    102. axis: 'left',
    103. xField: 'date',
    104. yField: 'visits',
    105. label: {
    106. display: 'none',
    107. field: 'visits',
    108. renderer: function(v) { return v >> 0; },
    109. 'text-anchor': 'middle'
    110. },
    111. markerConfig: {
    112. radius: 5,
    113. size: 5
    114. }
    115. },{
    116. type: 'line',
    117. axis: 'left',
    118. smooth: false,
    119. xField: 'date',
    120. yField: 'views',
    121. label: {
    122. display: 'none',
    123. field: 'visits',
    124. renderer: function(v) { return v >> 0; },
    125. 'text-anchor': 'middle'
    126. },
    127. markerConfig: {
    128. radius: 5,
    129. size: 5
    130. }
    131. },{
    132. type: 'line',
    133. axis: 'left',
    134. smooth: false,
    135. xField: 'date',
    136. yField: 'users',
    137. label: {
    138. display: 'none',
    139. field: 'visits',
    140. renderer: function(v) { return v >> 0; },
    141. 'text-anchor': 'middle'
    142. },
    143. markerConfig: {
    144. radius: 5,
    145. size: 5
    146. }
    147. }]
    148. }]
    149. });
    150. chart = Ext.getCmp('chartCmp');
    151. var timeAxis = chart.axes.get(1);
  • demo.js(加)
    1. var columnStore11 = Ext.create('Ext.data.JsonStore', {
    2. fields: ['name', 'data'],
    3. data: [
    4. {name:"0~10岁",data:20},
    5. {name:"11~18岁",data:60},
    6. {name:"19~24岁",data:30}
    7. ]
    8. });
    9. var b11 = Ext.create('Ext.Window', {
    10. width: 800,
    11. height: 600,
    12. hidden: false,
    13. maximizable: true,
    14. title: 'Pie Renderer Chart',
    15. renderTo: Ext.getBody(),
    16. layout: 'fit',
    17. tbar: [{
    18. text: 'Reload Data',
    19. handler: function() {
    20. columnStore11.loadData([
    21. {name:"0~10岁",data:40},
    22. {name:"11~18岁",data:20},
    23. {name:"19~24岁",data:40}
    24. ]);
    25. }
    26. }],
    27. items: {
    28. id: 'chartCmp',
    29. xtype: 'chart',
    30. style: 'background:#fff',
    31. animate: true,
    32. shadow: true,
    33. store: columnStore11,
    34. series: [{
    35. type: 'pie',
    36. animate: true,
    37. angleField: 'data', //角度
    38. lengthField: 'data', //字段切点长度
    39. highlight: {
    40. segment: {
    41. margin: 20
    42. }
    43. },
    44. label: {
    45. field: 'name', //文本标注
    46. display: 'rotate', //旋转标签 (also middle, out).
    47. font: '14px Arial',
    48. contrast: true
    49. },
    50. style: {
    51. 'stroke-width': 1,
    52. 'stroke': '#fff'
    53. },
    54. //add renderer
    55. renderer: function(sprite, record, attr, index, store) {//格式化重要函数
    56. var value = (record.get('data') >> 0) % 9;
    57. var color = [ "#94ae0a", "#115fa6","#a61120", "#ff8809", "#ffd13e", "#a61187", "#24ad9a", "#7c7474", "#a66111"][value];
    58. return Ext.apply(attr, {
    59. fill: color
    60. });
    61. }
    62. }]
    63. }
    64. });
  • Numeric.js
    1. Ext.onReady(function(){
    2. Ext.get("b1").on("click",function(){
    3. b1.show()
    4. })
    5. Ext.get("b2").on("click",function(){
    6. b2.show()
    7. })
    8. Ext.get("b3").on("click",function(){
    9. b3.show()
    10. })
    11. Ext.get("b4").on("click",function(){
    12. b4.show()
    13. })
    14. Ext.get("b5").on("click",function(){
    15. b5.show()
    16. })
    17. Ext.get("b6").on("click",function(){
    18. b6.show()
    19. })
    20. Ext.get("b7").on("click",function(){
    21. b7.show()
    22. })
    23. Ext.get("b8").on("click",function(){
    24. b8.show()
    25. })
    26. Ext.get("b9").on("click",function(){
    27. b9.show()
    28. })
    29. Ext.get("b10").on("click",function(){
    30. b10.show()
    31. })
    32. Ext.get("b11").on("click",function(){
    33. b11.show()
    34. })
    35. });

Ext.js高级组件的更多相关文章

  1. 谈谈Ext JS的组件——组件基类:Ext.Component

    概述 Ext.Component是所有Ext组件的基类,这在Ext.Component的API中第一句话就提到了.然后第二段说明了它包含的基本功能:隐藏/显示.启用/禁用以及尺寸控制等.除了以上这些基 ...

  2. 谈谈Ext JS的组件——布局的用法

    概述 在Ext JS中.包括两类布局:组件类布局和容器类布局.由于有些组件是有不同的组件组合而成的,如字段就由标题和输入框构成,他们之间也是存在布局关系的,而这就须要组件类布局来处理组件内自己特有的布 ...

  3. 谈谈Ext JS的组件——布局的用法续二

    绝对布局(Ext.layout.container.Absolute) 绝对布局让我回忆到了使用Foxpro开发的时候,哪时候的界面布局就是这样.通过设置控件的左上角坐标(x.y)和宽度来进行的,由于 ...

  4. 谈谈Ext JS的组件——布局的使用方法续二

    绝对布局(Ext.layout.container.Absolute) 绝对布局让我回想到了使用Foxpro开发的时候,哪时候的界面布局就是这样,通过设置控件的左上角坐标(x,y)和宽度来进行的,因为 ...

  5. 谈谈Ext JS的组件——布局的使用方法

    概述 在Ext JS中,包含两类布局:组件类布局和容器类布局.由于有些组件是有不同的组件组合而成的,如字段就由标题和输入框构成,他们之间也是存在布局关系的,而这就需要组件类布局来处理组件内自己特有的布 ...

  6. 谈谈Ext JS的组件——容器与布局

    概述 在页面中,比较棘手的地方就是布局.而要实现布局,就得有能维护布局的容器.可以说,在我试过和使用过的Javascript框架中,Ext JS的布局是做得最棒的一个,而这得益于它强大的容器类和丰富的 ...

  7. 谈谈Ext JS的组件——布局的使用方法续一

    盒子布局 盒子布局主要作用是以水平(Ext.layout.container.HBox)或垂直方式(Ext.layout.container.VBox)来划分容器区域.这也是比较常有的布局方式. 使用 ...

  8. 谈谈Ext JS的组件——布局的用法续一

    盒子布局 盒子布局主要作用是以水平(Ext.layout.container.HBox)或垂直方式(Ext.layout.container.VBox)来划分容器区域.这也是比較常有的布局方式. 使用 ...

  9. Ext学习-高级组件介绍

    在这一部分的学习中,主要是学习一些比较特殊的组件. 1.图表 2.日历 3.颜色,日期,时间的选择器 4.滑动条 5.各种工具类 参考文档:http://docs.sencha.com/extjs/4 ...

随机推荐

  1. java基础类型中的char和byte的辨析及Unicode编码和UTF-8的区别

    在平常工作中使用到char和byte的场景不多,但是如果项目中使用到IO流操作时,则必定会涉及到这两个类型,下面让我们一起来回顾一下这两个类型吧. char和byte的对比 byte byte 字节, ...

  2. numpy模块学习笔记

    # encoding=utf-8 import numpy as np from numpy.linalg import * def main(): # 1.最基本的array lst = [[1, ...

  3. Qt信号和槽连接方式的选择

    看了下Qt的帮助文档,发现connect函数最后还有一个缺省参数. connect函数原型是这样的: QMetaObject::Connection QObject::connect(const QO ...

  4. linux查看tftp服务是否启动

    netstat -a |grep tftp 若输出以下信息说明tftp服务已启动: udp  0 0 *:tftp *:*

  5. nginx限制蜘蛛的频繁抓取

    蜘蛛抓取量骤增,导致服务器负载很高.最终用nginx的ngx_http_limit_req_module模块限制了百度蜘蛛的抓取频率.每分钟允许百度蜘蛛抓取200次,多余的抓取请求返回503. ngi ...

  6. xlrd基本操作

    #coding=utf-8import xlrd def read_excel(): workbook = xlrd.open_workbook('people.xlsx') sheet2 = wor ...

  7. python 将类属性转为字典

    class dictObj(object): def __init__(self): self.x = 'red' self.y = 'Yellow' self.z = 'Green' def do_ ...

  8. JAVA消息 AMQP

    AMQP(Advanced Message Queuing Protocol)高级的消息队列

  9. C#通过WMI读取MAC地址

    该方法依赖WMI的系统服务,该服务一般不会被关闭;但如果系统服务缺失或者出现问题,该方法无法取得MAC地址,需要重启Windows Management Instrumentation服务. publ ...

  10. hadoop 集群配置--增加减少新的机器不重启

    增加机器不重启操作如下: 首先,把新节点的 IP或主机名 加入主节点(master)的 conf/slaves 文件. 然后登录新的从节点,执行以下命令: $ cd path/to/hadoop $ ...