PDA

View Full Version : TIP: Formatting file size



cadudecastroalves
23 Jan 2008, 5:45 AM
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:


function displayQuota(value) {
if(value == 0) {
var quota = 'Unlimited';
} else {
var quota = Ext.util.Format.fileSize(value);
}
return quota;
}


Example usage:


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

manu
23 Jan 2008, 6:16 AM
What do you think about:



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

cadudecastroalves
23 Jan 2008, 10:29 AM
Nice, manu. Thanks!