// 重写ext组件
Ext.BLANK_IMAGE_URL = '/images/public/s.gif"';
/**
* 允许直接修改label显示值
*/
Ext.override(Ext.form.Label, {
setText : function(t) {
this.text = t;
if (this.rendered) {
this.el.update(t);
}
},
setValue : function(t) {
this.text = t;
if (this.rendered) {
this.el.update(t);
}
}
});
/**
* 重写 Ext.util.Format.usMoney
*
* @param {}
* v
* @param {}
* meta
* @param {}
* record
* @return {String}
*/
Ext.util.Format.usMoney = function(v, meta, record) { // override
// Ext.util.usMoney
if (v==='') {
v=0;
}
if(isNaN(v)){
v = Ext.num(Number(v), 0); // ensure v is a valid numeric value, otherwise
}
// use 0 as
// a base (fixes $NaN.00 appearing in summaryRow when no
// records exist)
v = String(v);
var ps = v.split('.');
var whole = ps[0];
var sub = ps[1] ? '.' + ps[1] : '.00';
var r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
if (v.charAt(0) == '-') {
return '-' + v.substr(1);
}
return '' + v;
}
Ext.util.Format.cnMoney = function(v, meta, record) { // override
// Ext.util.usMoney
v = Ext.num(Number(v), 0); // ensure v is a valid numeric value, otherwise
// use 0 as
// a base (fixes $NaN.00 appearing in summaryRow when no
// records exist)
v = (Math.round((v - 0) * 100)) / 100;
v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v
+ "0" : v);
v = String(v);
var ps = v.split('.');
var whole = ps[0];
var sub = ps[1] ? '.' + ps[1] : '.00';
var r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
if (v.charAt(0) == '-') {
return '-' + v.substr(1);
}
return '' + v;
}
//渲染查询界面的金额数据格式
Ext.util.Format.SearchMoney = function(v, meta, record) { // override
// Ext.util.usMoney
if(isNaN(v)){
v = 0; // ensure v is a valid numeric value, otherwise
}
if(v==0){
return '';// ensure v is a valid numeric value, otherwise
}
// use 0 as
// a base (fixes $NaN.00 appearing in summaryRow when no
// records exist)
// v = (Math.round((v - 0) * 100)) / 100;
// v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v
// + "0" : v);
v = String(v);
var ps = v.split('.');
var whole = ps[0];
var sub = ps[1] ? '.' + ps[1] : '.00';
var r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
if (v.charAt(0) == '-') {
return '-' + v.substr(1);
}
return '' + v;
}
/**
* 限制textfield输入长度 属性设置 "lockLength" true/false
*
* 设置空格也作为未填验证处理
*
* @type Number
*/
Ext.override(Ext.form.Field, {
size : 20,
initValue : function() {
if (this.value !== undefined) {
this.setValue(this.value);
} else if (this.el.dom.value.length > 0) {
this.setValue(this.el.dom.value);
}
this.el.dom.size = this.size;
if (this.lockLength === true) {
if (!isNaN(this.maxLength) && (this.maxLength * 1) > 0
&& (this.maxLength != Number.MAX_VALUE)) {
this.el.dom.maxLength = this.maxLength;
}
}
},
validator : function(text) {
if (this.allowBlank == false
&& Ext.util.Format.trim(text).length == 0)
return false;
else
return true;
},
setFieldLabel: function(text){
// var r = this.getEl().up('div.x-form-item');
// r.dom.firstChild.firstChild.nodeValue = String.format('{0}', text);
if (this.rendered) {
this.el.up('.x-form-item', 10, true).child('.x-form-item-label').update(text);
}
this.fieldLabel = text;
}
});
/**
* 限制textArea输入长度 属性设置 "lockLength" true/false
*
* 设置空格也作为未填验证处理
*
* @type TextArea
*/
Ext.override(Ext.form.TextArea, {
size : 20,
lockLength:true,
initValue : function() {
if (this.value !== undefined) {
this.setValue(this.value);
} else if (this.el.dom.value.length > 0) {
this.setValue(this.el.dom.value);
}
this.el.dom.size = this.size;
if (this.lockLength === true) {
if (!isNaN(this.maxLength) && (this.maxLength * 1) > 0
&& (this.maxLength != Number.MAX_VALUE)) {
Extjs重写
最新推荐文章于 2019-02-21 15:43:21 发布
这篇博客主要介绍了如何重写ExtJS中的组件功能,包括修改Label显示值、自定义货币格式化函数、限制输入长度、扩展TreeLoader、为ComboBox添加keyup事件以及修复一些已知问题。通过这些优化,可以提升ExtJS应用的用户体验和性能。
摘要由CSDN通过智能技术生成