grid-plugins.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:10k
源码类别:

中间件编程

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.0.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */
  2. Ext.onReady(function(){
  3.     Ext.QuickTips.init();
  4.     var xg = Ext.grid;
  5.     // shared reader
  6.     var reader = new Ext.data.ArrayReader({}, [
  7.        {name: 'company'},
  8.        {name: 'price', type: 'float'},
  9.        {name: 'change', type: 'float'},
  10.        {name: 'pctChange', type: 'float'},
  11.        {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'},
  12.        {name: 'industry'},
  13.        {name: 'desc'}
  14.     ]);
  15.     ////////////////////////////////////////////////////////////////////////////////////////
  16.     // Grid 1
  17.     ////////////////////////////////////////////////////////////////////////////////////////
  18.     // row expander
  19.     var expander = new Ext.ux.grid.RowExpander({
  20.         tpl : new Ext.Template(
  21.             '<p><b>Company:</b> {company}</p><br>',
  22.             '<p><b>Summary:</b> {desc}</p>'
  23.         )
  24.     });
  25.     var grid1 = new xg.GridPanel({
  26.         store: new Ext.data.Store({
  27.             reader: reader,
  28.             data: xg.dummyData
  29.         }),
  30.         cm: new xg.ColumnModel({
  31.             defaults: {
  32.                 width: 20,
  33.                 sortable: true
  34.             },
  35.             columns: [
  36.                 expander,
  37.                 {id:'company',header: "Company", width: 40, dataIndex: 'company'},
  38.                 {header: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  39.                 {header: "Change", dataIndex: 'change'},
  40.                 {header: "% Change", dataIndex: 'pctChange'},
  41.                 {header: "Last Updated", renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  42.             ]
  43.         }),
  44.         viewConfig: {
  45.             forceFit:true
  46.         },
  47.         columnLines: true,
  48.         width: 600,
  49.         height: 300,
  50.         plugins: expander,
  51.         collapsible: true,
  52.         animCollapse: false,
  53.         title: 'Expander Rows, Collapse and Force Fit',
  54.         iconCls: 'icon-grid',
  55.         renderTo: document.body
  56.     });
  57.     ////////////////////////////////////////////////////////////////////////////////////////
  58.     // Grid 2
  59.     ////////////////////////////////////////////////////////////////////////////////////////
  60.     var sm = new xg.CheckboxSelectionModel();
  61.     var grid2 = new xg.GridPanel({
  62.         store: new Ext.data.Store({
  63.             reader: reader,
  64.             data: xg.dummyData
  65.         }),
  66.         cm: new xg.ColumnModel({
  67.             defaults: {
  68.                 width: 120,
  69.                 sortable: true
  70.             },
  71.             columns: [
  72.                 sm,
  73.                 {id:'company',header: "Company", width: 200, dataIndex: 'company'},
  74.                 {header: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  75.                 {header: "Change", dataIndex: 'change'},
  76.                 {header: "% Change", dataIndex: 'pctChange'},
  77.                 {header: "Last Updated", width: 135, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  78.             ]
  79.         }),
  80.         sm: sm,
  81.         columnLines: true,
  82.         width:600,
  83.         height:300,
  84.         frame:true,
  85.         title:'Framed with Checkbox Selection and Horizontal Scrolling',
  86.         iconCls:'icon-grid',
  87.         renderTo: document.body
  88.     });
  89.     ////////////////////////////////////////////////////////////////////////////////////////
  90.     // Grid 3
  91.     ////////////////////////////////////////////////////////////////////////////////////////
  92.     var grid3 = new xg.GridPanel({
  93.         store: new Ext.data.Store({
  94.             reader: reader,
  95.             data: xg.dummyData
  96.         }),
  97.         cm: new xg.ColumnModel([
  98.             new xg.RowNumberer(),
  99.             {id:'company',header: "Company", width: 40, sortable: true, dataIndex: 'company'},
  100.             {header: "Price", width: 20, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  101.             {header: "Change", width: 20, sortable: true, dataIndex: 'change'},
  102.             {header: "% Change", width: 20, sortable: true, dataIndex: 'pctChange'},
  103.             {header: "Last Updated", width: 20, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  104.         ]),
  105.         viewConfig: {
  106.             forceFit:true
  107.         },
  108.         columnLines: true,
  109.         width:600,
  110.         height:300,
  111.         title:'Grid with Numbered Rows and Force Fit',
  112.         iconCls:'icon-grid',
  113.         renderTo: document.body
  114.     });
  115.     ////////////////////////////////////////////////////////////////////////////////////////
  116.     // Grid 4
  117.     ////////////////////////////////////////////////////////////////////////////////////////
  118.     var sm2 = new xg.CheckboxSelectionModel({
  119.         listeners: {
  120.             // On selection change, set enabled state of the removeButton
  121.             // which was placed into the GridPanel using the ref config
  122.             selectionchange: function(sm) {
  123.                 if (sm.getCount()) {
  124.                     grid4.removeButton.enable();
  125.                 } else {
  126.                     grid4.removeButton.disable();
  127.                 }
  128.             }
  129.         }
  130.     });
  131.     var grid4 = new xg.GridPanel({
  132.         id:'button-grid',
  133.         store: new Ext.data.Store({
  134.             reader: reader,
  135.             data: xg.dummyData
  136.         }),
  137.         cm: new xg.ColumnModel([
  138.             sm2,
  139.             {id:'company',header: "Company", width: 40, sortable: true, dataIndex: 'company'},
  140.             {header: "Price", width: 20, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  141.             {header: "Change", width: 20, sortable: true, dataIndex: 'change'},
  142.             {header: "% Change", width: 20, sortable: true, dataIndex: 'pctChange'},
  143.             {header: "Last Updated", width: 20, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  144.         ]),
  145.         sm: sm2,
  146.         viewConfig: {
  147.             forceFit:true
  148.         },
  149.         columnLines: true,
  150.         // inline buttons
  151.         buttons: [{text:'Save'},{text:'Cancel'}],
  152.         buttonAlign:'center',
  153.         // inline toolbars
  154.         tbar:[{
  155.             text:'Add Something',
  156.             tooltip:'Add a new row',
  157.             iconCls:'add'
  158.         }, '-', {
  159.             text:'Options',
  160.             tooltip:'Blah blah blah blaht',
  161.             iconCls:'option'
  162.         },'-',{
  163.             text:'Remove Something',
  164.             tooltip:'Remove the selected item',
  165.             iconCls:'remove',
  166.             // Place a reference in the GridPanel
  167.             ref: '../removeButton',
  168.             disabled: true
  169.         }],
  170.         width:600,
  171.         height:300,
  172.         frame:true,
  173.         title:'Support for standard Panel features such as framing, buttons and toolbars',
  174.         iconCls:'icon-grid',
  175.         renderTo: document.body
  176.     });
  177. });
  178. // Array data for the grids
  179. Ext.grid.dummyData = [
  180.     ['3m Co',71.72,0.02,0.03,'9/1 12:00am', 'Manufacturing'],
  181.     ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am', 'Manufacturing'],
  182.     ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am', 'Manufacturing'],
  183.     ['American Express Company',52.55,0.01,0.02,'9/1 12:00am', 'Finance'],
  184.     ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am', 'Services'],
  185.     ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am', 'Services'],
  186.     ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am', 'Manufacturing'],
  187.     ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am', 'Services'],
  188.     ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am', 'Finance'],
  189.     ['E.I. du Pont de Nemours and Company',40.48,0.51,1.28,'9/1 12:00am', 'Manufacturing'],
  190.     ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am', 'Manufacturing'],
  191.     ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am', 'Manufacturing'],
  192.     ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am', 'Automotive'],
  193.     ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am', 'Computer'],
  194.     ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am', 'Manufacturing'],
  195.     ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am', 'Computer'],
  196.     ['International Business Machines',81.41,0.44,0.54,'9/1 12:00am', 'Computer'],
  197.     ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am', 'Medical'],
  198.     ['JP Morgan & Chase & Co',45.73,0.07,0.15,'9/1 12:00am', 'Finance'],
  199.     ['McDonald's Corporation',36.76,0.86,2.40,'9/1 12:00am', 'Food'],
  200.     ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am', 'Medical'],
  201.     ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am', 'Computer'],
  202.     ['Pfizer Inc',27.96,0.4,1.45,'9/1 12:00am', 'Services', 'Medical'],
  203.     ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am', 'Food'],
  204.     ['The Home Depot, Inc.',34.64,0.35,1.02,'9/1 12:00am', 'Retail'],
  205.     ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am', 'Manufacturing'],
  206.     ['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am', 'Computer'],
  207.     ['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am', 'Services'],
  208.     ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am', 'Retail'],
  209.     ['Walt Disney Company (The) (Holding Company)',29.89,0.24,0.81,'9/1 12:00am', 'Services']
  210. ];
  211. // add in some dummy descriptions
  212. for(var i = 0; i < Ext.grid.dummyData.length; i++){
  213.     Ext.grid.dummyData[i].push('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.<br/><br/>Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit.');
  214. }