3.2.0

Sorting problem with date and size

I use it to list and display files and folder (using php script), but I have a problem in two column date modified and size
I have following values in size column
1 KB
70 KB
65 KB
101 KB
105 KB

so when i do sort, i get following result
1 KB
101 KB
105 KB
65 KB
70 KB

instead of
1 KB
65 KB
70 KB
101 KB
105 KB.

Also same is happening with date, I have got following value in date modified column
May
June
July
April
Feb

So when I sort it gives following result
April
Feb
July
June
May

instead of
Feb
April
May
June
July

Is there any way to achive this type of sorting?






M Sharma
June 2,
Also I am doing sorting for root using
http://www.activewidgets.com/messages/767-4.htm
link.
Alex, Pls help.
M Sharma
June 2,
You have to create your own data/value functions which transform your cell text to numeric value (for sorting) like here:

http://www.activewidgets.com/messages/1025-8.htm
Alex (ActiveWidgets)
June 3,
Hi Alex,
Thanks, I have fixed the problem of date sorting. But can you please give an example how to fix the size column sorting problem having values
1 KB
101 KB
105 KB
65 KB
70 KB


M Sharma
June 4,
You need to create your custom type and stick it into the /formats/ folder and then reference it in the grid.js file. When using this type don't forget the value is the size in bytes which is then formatted by the format display function.

Cheers
Tali



Active.Formats.NumberK = Active.System.Format.subclass();

Active.Formats.NumberK.create = function(){

/****************************************************************

Number formatting class.

*****************************************************************/

var obj = this.prototype;

/****************************************************************

Transforms the wire data into the numeric value.

@param data (String) Wire data.
@return Numeric value.

*****************************************************************/

obj.dataToValue = function(data){
return Number(data);
};

/****************************************************************

Transforms the wire data into the readable text.

@param data (String) Wire data.
@return Readable text.

*****************************************************************/
function round_decimals(original_number, decimals) {
var result1 = original_number * Math.pow(10, decimals)
var result2 = Math.round(result1)
var result3 = result2 / Math.pow(10, decimals)
return result3
}


obj.dataToText = function(size)
{
if (size < 0)
{
return '&nbsp;';
}
else if(size < 1024)
{
return size + ' B';
}
else if(size / 1024 < 1024)
{
size = round_decimals(size / 1024,2);
return size + ' KB';
}
else if(size / 1024 / 1024 < 1024)
{
size = round_decimals(size / 1024 / 1024,2);
return size + ' MB';
}
else if(size / 1024 / 1024 / 1024 < 1024)
{
size = round_decimals(size / 1024 / 1024 / 1024,2);
return size + ' GB';
}
else
{
size = round_decimals(size / 1024 / 1024 / 1024 / 1024,2);
return size + ' TB';
}
};
};

Active.Formats.NumberK.create();
June 9,

This topic is archived.

See also:


Back to support forum