1. #1
    Ext User cadudecastroalves's Avatar
    Join Date
    Mar 2007
    Location
    Rio de Janeiro, Brazil
    Posts
    98
    Vote Rating
    0
    cadudecastroalves is on a distinguished road

      0  

    Thumbs up TIP: Formatting file size

    TIP: Formatting file size


    Hello people.

    I've been developing an application and I'd like to share a little and simple tip. In my application, I've a grid that shows information about domains (similar to a CPanel or Plesk domain manager). One of these columns is Quota that shows to the user how much space the domains have.

    In my application, I defined that each quota value equals 0 is a quota with unlimited space. So, I created a little function using the format method fileSize() to show the quota size.

    Here's my contribution. It's simple, but very useful.

    displayQuota() method:
    Code:
    function displayQuota(value) {
    	if(value == 0) {
    		var quota = 'Unlimited';
    	} else {
    		var quota = Ext.util.Format.fileSize(value);
    	}
    	return quota;
    }
    Example usage:
    Code:
    var colModel = new Ext.grid.ColumnModel([
    	{header: "Account", width: 150, sortable: true},
    	{header: "Domain", width: 150, sortable: true},
    	{header: "Quota", width: 80, renderer: displayQuota, sortable: true},
    	{header: "Status", width: 30, sortable: true}
     ]);
    Cadu de Castro Alves
    Ext-user
    http://www.cadudecastroalves.com/

  2. #2
    Ext User
    Join Date
    Dec 2007
    Location
    Darmstadt, Germany
    Posts
    3
    Vote Rating
    0
    manu is on a distinguished road

      0  

    Default


    What do you think about:

    Code:
    function displayQuota(value) {
        return (value == 0) ? 'Unlimited' : Ext.util.Format.fileSize(value);
    }

  3. #3
    Ext User cadudecastroalves's Avatar
    Join Date
    Mar 2007
    Location
    Rio de Janeiro, Brazil
    Posts
    98
    Vote Rating
    0
    cadudecastroalves is on a distinguished road

      0  

    Default


    Nice, manu. Thanks!
    Cadu de Castro Alves
    Ext-user
    http://www.cadudecastroalves.com/

Thread Participants: 1