grid-plugins.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:10k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.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.         width: 600,
  48.         height: 300,
  49.         plugins: expander,
  50.         collapsible: true,
  51.         animCollapse: false,
  52.         title: 'Expander Rows, Collapse and Force Fit',
  53.         iconCls: 'icon-grid',
  54.         renderTo: document.body
  55.     });
  56.     ////////////////////////////////////////////////////////////////////////////////////////
  57.     // Grid 2
  58.     ////////////////////////////////////////////////////////////////////////////////////////
  59.     var sm = new xg.CheckboxSelectionModel();
  60.     var grid2 = new xg.GridPanel({
  61.         store: new Ext.data.Store({
  62.             reader: reader,
  63.             data: xg.dummyData
  64.         }),
  65.         cm: new xg.ColumnModel({
  66.             defaults: {
  67.                 width: 120,
  68.                 sortable: true
  69.             },
  70.             columns: [
  71.                 sm,
  72.                 {id:'company',header: "Company", width: 200, dataIndex: 'company'},
  73.                 {header: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  74.                 {header: "Change", dataIndex: 'change'},
  75.                 {header: "% Change", dataIndex: 'pctChange'},
  76.                 {header: "Last Updated", width: 135, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  77.             ]
  78.         }),
  79.         sm: sm,
  80.         columnLines: true,
  81.         width:600,
  82.         height:300,
  83.         frame:true,
  84.         title:'Framed with Checkbox Selection and Horizontal Scrolling',
  85.         iconCls:'icon-grid',
  86.         renderTo: document.body
  87.     });
  88.     ////////////////////////////////////////////////////////////////////////////////////////
  89.     // Grid 3
  90.     ////////////////////////////////////////////////////////////////////////////////////////
  91.     var grid3 = new xg.GridPanel({
  92.         store: new Ext.data.Store({
  93.             reader: reader,
  94.             data: xg.dummyData
  95.         }),
  96.         cm: new xg.ColumnModel([
  97.             new xg.RowNumberer(),
  98.             {id:'company',header: "Company", width: 40, sortable: true, dataIndex: 'company'},
  99.             {header: "Price", width: 20, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  100.             {header: "Change", width: 20, sortable: true, dataIndex: 'change'},
  101.             {header: "% Change", width: 20, sortable: true, dataIndex: 'pctChange'},
  102.             {header: "Last Updated", width: 20, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  103.         ]),
  104.         viewConfig: {
  105.             forceFit:true
  106.         },
  107.         columnLines: true,
  108.         width:600,
  109.         height:300,
  110.         title:'Grid with Numbered Rows and Force Fit',
  111.         iconCls:'icon-grid',
  112.         renderTo: document.body
  113.     });
  114.     ////////////////////////////////////////////////////////////////////////////////////////
  115.     // Grid 4
  116.     ////////////////////////////////////////////////////////////////////////////////////////
  117.     var sm2 = new xg.CheckboxSelectionModel({
  118.         listeners: {
  119.             // On selection change, set enabled state of the removeButton
  120.             // which was placed into the GridPanel using the ref config
  121.             selectionchange: function(sm) {
  122.                 if (sm.getCount()) {
  123.                     grid4.removeButton.enable();
  124.                 } else {
  125.                     grid4.removeButton.disable();
  126.                 }
  127.             }
  128.         }
  129.     });
  130.     var grid4 = new xg.GridPanel({
  131.         id:'button-grid',
  132.         store: new Ext.data.Store({
  133.             reader: reader,
  134.             data: xg.dummyData
  135.         }),
  136.         cm: new xg.ColumnModel([
  137.             sm2,
  138.             {id:'company',header: "Company", width: 40, sortable: true, dataIndex: 'company'},
  139.             {header: "Price", width: 20, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  140.             {header: "Change", width: 20, sortable: true, dataIndex: 'change'},
  141.             {header: "% Change", width: 20, sortable: true, dataIndex: 'pctChange'},
  142.             {header: "Last Updated", width: 20, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  143.         ]),
  144.         sm: sm2,
  145.         viewConfig: {
  146.             forceFit:true
  147.         },
  148.         columnLines: true,
  149.         // inline buttons
  150.         buttons: [{text:'Save'},{text:'Cancel'}],
  151.         buttonAlign:'center',
  152.         // inline toolbars
  153.         tbar:[{
  154.             text:'Add Something',
  155.             tooltip:'Add a new row',
  156.             iconCls:'add'
  157.         }, '-', {
  158.             text:'Options',
  159.             tooltip:'Blah blah blah blaht',
  160.             iconCls:'option'
  161.         },'-',{
  162.             text:'Remove Something',
  163.             tooltip:'Remove the selected item',
  164.             iconCls:'remove',
  165.             // Place a reference in the GridPanel
  166.             ref: '../removeButton',
  167.             disabled: true
  168.         }],
  169.         width:600,
  170.         height:300,
  171.         frame:true,
  172.         title:'Support for standard Panel features such as framing, buttons and toolbars',
  173.         iconCls:'icon-grid',
  174.         renderTo: document.body
  175.     });
  176. });
  177. // Array data for the grids
  178. Ext.grid.dummyData = [
  179.     ['3m Co',71.72,0.02,0.03,'9/1 12:00am', 'Manufacturing'],
  180.     ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am', 'Manufacturing'],
  181.     ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am', 'Manufacturing'],
  182.     ['American Express Company',52.55,0.01,0.02,'9/1 12:00am', 'Finance'],
  183.     ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am', 'Services'],
  184.     ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am', 'Services'],
  185.     ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am', 'Manufacturing'],
  186.     ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am', 'Services'],
  187.     ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am', 'Finance'],
  188.     ['E.I. du Pont de Nemours and Company',40.48,0.51,1.28,'9/1 12:00am', 'Manufacturing'],
  189.     ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am', 'Manufacturing'],
  190.     ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am', 'Manufacturing'],
  191.     ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am', 'Automotive'],
  192.     ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am', 'Computer'],
  193.     ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am', 'Manufacturing'],
  194.     ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am', 'Computer'],
  195.     ['International Business Machines',81.41,0.44,0.54,'9/1 12:00am', 'Computer'],
  196.     ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am', 'Medical'],
  197.     ['JP Morgan & Chase & Co',45.73,0.07,0.15,'9/1 12:00am', 'Finance'],
  198.     ['McDonald's Corporation',36.76,0.86,2.40,'9/1 12:00am', 'Food'],
  199.     ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am', 'Medical'],
  200.     ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am', 'Computer'],
  201.     ['Pfizer Inc',27.96,0.4,1.45,'9/1 12:00am', 'Services', 'Medical'],
  202.     ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am', 'Food'],
  203.     ['The Home Depot, Inc.',34.64,0.35,1.02,'9/1 12:00am', 'Retail'],
  204.     ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am', 'Manufacturing'],
  205.     ['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am', 'Computer'],
  206.     ['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am', 'Services'],
  207.     ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am', 'Retail'],
  208.     ['Walt Disney Company (The) (Holding Company)',29.89,0.24,0.81,'9/1 12:00am', 'Services']
  209. ];
  210. // add in some dummy descriptions
  211. for(var i = 0; i < Ext.grid.dummyData.length; i++){
  212.     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.');
  213. }