Hi,

For the various FileDetailV2 lists found in section attachments, it appears the FileSize column, (if added to the detail list columns to display,) only renders the value as the size in bytes.  What is the correct procedure to have that value shown instead in kilo/megabytes, with appropriate suffix?

ie instead of showing a value of '2,456,601' for the size of the file, instead show '2.456 MB' (if the file size >= 1 000 000 bytes).

If the value for file size is greater than 1 000 byes, but less than 1 000 000 ( 1000 <= x < 1000000) I'd like to have the value displayed as the file size value divided by 1000, to 3 decimal places with a suffix of 'KB' added.

In a more general scenario, how can fields within detail lists results be formatted through some callback function?  Does that need to be defined within the schema of the detail itself, overriding the prepareEntityLinkCollection function?  Or can this be done with field validation/input masks?

 

Thanks,

Lachlan Devantier

 

Like 1

Like

1 comments

Hi Lachlan,



In order to achieve that you should add your logic to the detail schema. Since size is an integer column and we want to display it with text ("kb", "mb", etc) I also modifed its attribute. In a detail there is a function prepareResponseCollection that can be used for such purposes.



See full sample below:

 

define("FileDetailV2", [],
	function() {
	return {
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
		attributes: {
			"Size": {
				"dataValueType": Terrasoft.DataValueType.TEXT
			}
		},
		methods: {
			prepareResponseCollection: function(collection) {
				this.callParent(arguments);
				collection.each(function(item) {
					this.fillInSizeColumn(item);
				}, this);
			},
			fillInSizeColumn: function(item) {
				var size = item.get("Size");
				//add your calculating logic here
				item.set("Size", (size / 1024) + " Kb");
			}
		}
	};
});

Result - https://prnt.sc/qiv9gs



Regards,

Dmytro

Show all comments