Apr 062011
 

Assalamu’ alaikum wr wb

Langsung saja berikut source nya :

Ext.override(Ext.form.TextField, {
  initComponent : function(){
    centsLimit = 2;
    centsSeparator = '.';
    thousandsSeparator = ',';
    limit = false;
    prefix = '';
  }
  ,to_numbers : function (str) {
    var formatted = '';
    var is_number = /[0-9]/;
    for (var i=0;i<(str.length);i++) {
      char = str.charAt(i);
      if (formatted.length==0 && char==0) char = false;
      if (char && char.match(is_number)) {
        if (limit) {
          if (formatted.length < limit) formatted = formatted+char;
        }else{
          formatted = formatted+char;
        }
      }
    }
    return formatted;
  }
  ,fill_with_zeroes : function(str){
    while (str.length<(centsLimit+1)) str = '0'+str;
      return str;
  }
  ,price_format : function (str) {
    var formatted = this.fill_with_zeroes(this.to_numbers(str));
    var thousandsFormatted = '';
    var thousandsCount = 0;
    var centsVal = formatted.substr(formatted.length-centsLimit,centsLimit);
    var integerVal = formatted.substr(0,formatted.length-centsLimit);
    formatted = integerVal+centsSeparator+centsVal;
      if (thousandsSeparator) {
        for (var j=integerVal.length;j>0;j--) {
          char = integerVal.substr(j-1,1);
          thousandsCount++;
          if (thousandsCount%3==0) char = thousandsSeparator+char;
          thousandsFormatted = char+thousandsFormatted;
        }
      if (thousandsFormatted.substr(0,1)==thousandsSeparator)
      thousandsFormatted = thousandsFormatted.substring(1,thousandsFormatted.length);
      formatted = thousandsFormatted+centsSeparator+centsVal;
    }
    if (prefix) formatted = prefix+formatted;
      return formatted;
  }
  ,keydown : function(obj, evt){
     var code = (evt.keyCode ? evt.keyCode : evt.which);
     var typed = String.fromCharCode(code);
     var functional = false;
     var str = this.getValue();
     var newValue = this.price_format(str+typed);
     if(code >= 96 && code <= 105) functional = true;
     if (code ==  8) functional = true;
     if (code ==  9) functional = true;
     if (code == 13) functional = true;
     if (code == 37) functional = true;
     if (code == 39) functional = true;
     if (!functional) {
       if (str!=newValue) this.setValue(newValue);
     }
  }
  ,keyup : function () {
    var str = this.getValue();
    var price = this.price_format(str);
    if (str != price) this.setValue(price);
  }
  ,initEvents : function() {
     this.el.on("keydown", this.keydown, this);
     this.el.on("keyup", this.keyup, this);
  }
})

Facebook Comments

  11 Responses to “Price Format ExtJs / Curency Format Extjs / Number Format ExtJS”

  1. Terimakasih… 🙂

  2. mbah mau tanya nih, extjs dan ci …? kalau yang tutorial mbah kan pake extjs 3, klo extjs4+ci caranya gimana ya mbah, apa perbedaannya ?

  3. Bedanya klo pake ExtJS4 dengan versi sebelumnya sangat berbda pada beberapa cara penggunaannya. Pada ExtJs 4 sudah lebih OOP. nanti kalo sempat pasti saya buat deh tutorialnya

  4. ya mbah sambil menunggu extjs4+CI versi mbahsomo, saya masih terus coba2 nih, dah sedikit2 bisa tampilkan grid, tapi tetap ditunggu lho tips dan trik dari website ini… 🙂 hmmm, sukses mbahsomo… trims…

  5. Ok Mas Semoga tetep terus berkarya.

  6. yo mbah sukses selalu, ditunggu extjs4 with codeigniter… 🙂

  7. mbah somo, punya tutorial untuk login pengguna gak, jadi pengguna mempunyai 2 akses (aministrator, user-biasa), ketika dia login dengan status user-biasa… asumsi user-biasa ada 2 pengguna, nah 2 pengguna itu mengakses tabel yang sama didatabase, tapi 2 user-biasa itu hanya bisa melihat data masing2 yang di entrinkan,.. itu gimana ya mbah buat implementasikan di extjs… trims….

  8. Semoga nanti malam sempat untuk upload kalo sempat nanti malam Insa’Allah saya upload deh tutorilanya

  9. @ mbahsomo:
    alhamdulillah trimakasih mbah, mudah2an disempatkan waktunya, amin…. trims… 🙂

  10. Lingua de maluco!

  11. The beauty of life, always being ahead of her show; like the beauty of trees, is to show a negative trend in its vigor in the towering up; like the eagle’s beautiful, is to show the wind blow the rain in it, such as stroke flying in the heaven of the soul; like the beautiful rivers, is displayed in the torrent that it blew out in the rough.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)