]>
git.proxmox.com Git - extjs.git/blob - extjs/examples/classic/grid/buffer-grid.js
7 Ext
.define('Employee', {
8 extend
: 'Ext.data.Model',
19 convert: function (value
, record
) {
20 return record
.get('forename') + ' ' + record
.get('surname');
47 name
: 'holidayAllowance',
53 Ext
.onReady(function() {
55 function random(from, to
) {
56 return Math
.floor(Math
.random() * (to
- from + 1) + from);
59 function getEmployeeNo() {
69 * Returns an array of fake data
70 * @param {Number} count The number of fake rows to create data for
71 * @return {Array} The fake record data, suitable for usage with an ArrayReader
73 function createFakeData(count
, data
) {
74 var firstNames
= ['Ed', 'Tommy', 'Aaron', 'Abe', 'Jamie', 'Adam', 'Dave', 'David', 'Jay', 'Nicolas', 'Nige'],
75 lastNames
= ['Spencer', 'Maintz', 'Conran', 'Elias', 'Avins', 'Mishcon', 'Kaneda', 'Davis', 'Robinson', 'Ferrero', 'White'],
76 departments
= ['Engineering', 'Sales', 'Marketing', 'Managment', 'Support', 'Administration'],
77 ratings
= [1, 2, 3, 4, 5],
78 salaries
= [100, 400, 900, 1500, 1000000],
79 noticePeriods
= ['2 weeks', '1 month', '3 months'],
82 for (i
= 0; i
< (count
|| 25); i
++) {
83 var firstName
= firstNames
[random(0, firstNames
.length
- 1)],
84 lastName
= lastNames
[random(0, lastNames
.length
- 1)],
85 name
= Ext
.String
.format("{0} {1}", firstName
, lastName
),
86 email
= firstName
.toLowerCase() + '.' + lastName
.toLowerCase() + '@sentcha.com',
87 rating
= ratings
[(name
=== 'Nige White') ? 0 : random(0, ratings
.length
- 1)],
88 salary
= salaries
[(name
=== 'Nige White') ? 4 : random(0, salaries
.length
- 1)],
89 department
= departments
[random(0, departments
.length
- 1)],
90 ageInYears
= random(23, 55),
91 dob
= new Date(new Date().getFullYear() - ageInYears
, random(0, 11), random(0, 31)),
92 joinDate
= new Date(new Date() - random(60, 2000) * 1000 * 60 * 60 * 24),
93 sickDays
= random(0, 10),
94 holidayDays
= random(0, 10),
95 holidayAllowance
= random(20, 40);
98 employeeNo
: getEmployeeNo(),
104 department
: department
,
108 holidayDays
: holidayDays
,
109 holidayAllowance
: holidayAllowance
,
110 noticePeriod
: noticePeriods
[random(0, noticePeriods
.length
- 1)]
115 // Create the Data Store.
116 // Because it is buffered, the automatic load will be directed
117 // through the prefetch mechanism, and be read through the page cache
118 var store
= Ext
.create('Ext.data.Store', {
119 groupField
: 'department',
123 var jumpToRow = function(){
124 var fld
= grid
.down('#gotoLine');
126 grid
.view
.bufferedRenderer
.scrollTo(fld
.getValue() - 1, true);
134 var grid
= Ext
.create('Ext.grid.Panel', {
137 title
: 'Buffered Grid of 5,000 random records',
147 ftype
: 'groupingsummary',
148 groupHeaderTpl
: '{columnName}: {name}',
149 showSummaryRow
: false
153 xtype
: 'rownumberer',
159 dataIndex
: 'employeeNo',
169 text
: 'Date of birth',
175 dataIndex
: 'joinDate',
179 text
: 'Notice period',
180 dataIndex
: 'noticePeriod'
182 text
: 'Email address',
186 renderer: function(v
) {
187 return '<a href="mailto:' + v
+ '">' + v
+ '</a>';
191 dataIndex
: 'department',
197 dataIndex
: 'sickDays',
202 dataIndex
: 'holidayDays',
206 text
: 'Holiday Allowance',
207 dataIndex
: 'holidayAllowance',
223 renderer
: Ext
.util
.Format
.usMoney
,
228 fieldLabel
: 'Jump to row',
229 xtype
: 'numberfield',
232 allowDecimals
: false,
234 enableKeyEvents
: true,
236 specialkey: function(field
, e
){
237 if (e
.getKey() === e
.ENTER
) {
246 renderTo
: Ext
.getBody()
249 function makeData() {
250 createFakeData(perBatch
, data
);
251 if (data
.length
< max
) {
252 setTimeout(makeData
, 10);
255 store
.loadData(data
);
259 grid
.el
.mask('Generating fake data...');
261 // In old IE, the fake data loop can cause a slow script warning,
262 // so kick this off in the "background" to load the data in chunks.