Extjs 公共JS

1、人民币格式化

function rmbMoneyRender(v, cellmeta, record, rowIndex, columnIndex, stor){
if(!v && v != 0)
return '';
    v = (Math.round((v-0)*100))/100;
    v = (v == Math.floor(v)) ? v : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split('.');
    var whole = ps[0];
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, '$1' + ',' + '$2');
    }
    v = whole;
    if(v.charAt(0) == '-'){
    return '-' + v.substr(1);
    }
    return v;
};


引用:{header:'收入金额', dataIndex:'income', align:'right',renderer: rmbMoneyRender,sortable:true},


2、人民币格式化, 带两位小数点,没有则补齐两位

function rmbMoneyRenderDot(v, cellmeta, record, rowIndex, columnIndex, stor){
    if(!v && v != 0)
return '';

    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;
};

3、百分比格式化

function renderRatio(value, cellmeta, record, rowIndex, columnIndex, stor) {
if(!value && value != 0) return '';

//判断value后面的小数,如果只有一位的话补零
value = '' + value;
var ps = value.split('.');
var whole = ps[0];
var dot = '00';
if(ps.length > 1) {
dot = ps[1] + dot;
}
dot = dot.substring(0, 2);
value = whole + '.' + dot;
return value + '%';
}


function renderDotRatio(value, cellmeta, record, rowIndex, columnIndex, stor) {
if(!value && value != 0) return '';

value = value * 100;
//判断value后面的小数,如果只有一位的话补零
value = '' + value;
var ps = value.split('.');
var whole = ps[0];
var dot = '00';
if(ps.length > 1) {
dot = ps[1] + dot;
}
dot = dot.substring(0, 2);
value = whole + '.' + dot;
return value + '%';
}

function rmbMoneyRenderOld(v, cellmeta, record, rowIndex, columnIndex, stor){
    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;
};

4、单元格点击链接

function renderClickCell(v) {
if(!v) {
return '';
}
else if(v == '合计')
return '<font style="color: #DDDDDD;font-weight: bold;">' + v + '</font>';
else {
return '<font class="eddy-grid-link" style="cursor: pointer;text-decoration: underline;color: #379337;font-weight: bold;">' + v + '</font>';
}
}


5、人民币格式化且能点击

function renderClickCellMoney(v) {
if(!v) {
return '';
}
else if(v == '合计')
return '<font style="color: #DDDDDD;font-weight: bold;">' + v + '</font>';
else {
v = rmbMoneyRender(v);
return '<font class="eddy-grid-link" style="cursor: pointer;text-decoration: underline;color: #379337;font-weight: bold;">' + v + '</font>';
}
}


function renderClickCellMoneyDot(v) {
if(!v) {
return '';
}
else if(v == '合计')
return '<font style="color: #DDDDDD;font-weight: bold;">' + v + '</font>';
else {
v = rmbMoneyRenderDot(v);
return '<font class="eddy-grid-link" style="cursor: pointer;text-decoration: underline;color: #379337;font-weight: bold;">' + v + '</font>';
}
}


6、Json时间格式化

function renderJSONDate(format) {
return function(v) {
var jsonDateValue;
if(Ext.isEmpty(v)) {
return '';
}
else if(Ext.isEmpty(v.time)) {
jsonDateValue = new Date(v);
}
else {
jsonDateValue = new Date(v.time);
}
return jsonDateValue.format(format);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值