New useful store functions

Ext Class: 
Ext.data.store

Some useful additional store functions 

  • getEncodedData
  • setAll
  • getBetween
  • min
  • max

Install as follows

Ext.override(Ext.data.Store, { 
getEncodedData: function (modifiedOnly){ 
if(modifiedOnly === true) { 
c = this.getModifiedRecords(); 
} else { 
c = this.getRange(); 
} 
var p = new Array(); 
if(c.length){ 
for(i=0; i<c.length; i++) { 
p[i] = c[i].data; 
} 
return Ext.encode(p); 
} else { 
return ''; 
} 
}, 
setAll: function(f,v){ 
this.each(function(r){ 
r.set(f,v); 
}) 
}, 
getBetween: function(value, lower, upper){ 
var rc; 
this.each(function(r){ 
var d = r.data; 
if(value >= (1 * d[lower]) && value <= (1 * d[upper])) { 
rc = r; 
return false; 
} 
}); 
return rc; 
}, 
max : function(property,start,end){ 
var rs = this.data.items, v = 0; 
start = start || 0; 
end = (end || end === 0) ? end : rs.length-1; 
for(var i = start; i <= end; i++){ 
v = Math.max(v, (1 * rs[i].data[property]) || 0); 
} 
return v; 
}, 
min : function(property,start,end){ 
var rs = this.data.items, v = 0; 
start = start || 0; 
end = (end || end === 0) ? end : rs.length-1; 
for(var i = start; i <= end; i++){ 
v = Math.min(v, (1 * rs[i].data[property]) || 0); 
} 
return v; 
} 
})

 

Usage:

getEncodedData

Returns string encoded data suitable for submission in Ajax request. 

Parameters:

  • modifiedOnly - if true only returns modified records

getBetween

Returns array of records where value between lower and upper

Parameters:

  • value: the field to search in
  • lower: lower bound
  • upper: upper bound

max

Returns maximum value for field property between records start and end

Parameters:

  • property: field value to return max from
  • start: start index of records to search (default 0)
  • end: end index of records to search (default store.getCount()) 

setAll

Sets value of field f to value v for all records in the store

Parameters:

  • f: field to update
  • v: value to set field to

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
four times equals four
Solve this math question and enter the solution with digits. E.g. for "two plus four = ?" enter "6".