How can I customise Preside datatables?

I’m part of a team working on a site for a client who has needs financial info displayed. We’re using the enhancedDataManagerBase handler to display multiple tabs and within some of those tabs we’re currently rendering the admin.dataHelpers.relatedRecordsDatatable viewlet.

We’ve been asked to include the currency symbol and format amounts with a comma to 2 decimal places e.g. £12,000.00
We’ve currently partly done this using formula fields such as formula="CONCAT('£', FORMAT(${prefix}approved_amount, 2))" but have a couple of issues.
The first is that we need to do this on a property that is another formula field with an aggregate function in it and the formatting formula property is unable to reference the aggregate formula property.
The second is that on the properties we do have working, the datatable sorting doesn’t work as it’s sorting alphabetically.

So given all that, is there any way using Preside to have greater control over the built in datatables to allow us to make use of things like the built-in currency formatting or ability to set a different sort property than the display one? We could create a new view and add a datatable to that but hoping there might be other options.

I see what you’re trying to do and I think you just need a renderer (Preside Documentation :: Admin record views)

You can define a handlers/renderers/content/money.cfc and do this:

component {
	private string function default( event, rc, prc, args={} ){
		var data = args.data ?: "";

		if ( LSIsNumeric( data ) ) {
			return LSCurrencyFormat( data, 'local', 'en_gb' );
		}
		return "";
	}

	private string function adminDataTable( event, rc, prc, args={} ){
		var data = args.data ?: "";

		if ( LSIsNumeric( data ) ) {
			return LSCurrencyFormat( data, 'local', 'en_gb' );
		}
		return "";
	}
	
	private string function adminView( event, rc, prc, args={} ){
		var data = args.data ?: "";

		if ( LSIsNumeric( data ) ) {
			return LSCurrencyFormat( data, 'local', 'en_gb' );
		}
		return "";
	}		
}

And in your object definition you assign the renderer:

property name="amount" type="numeric" dbtype="decimal( 10, 2 )" renderer="money" adminRenderer="money";

Doing this you don’t have to deal with the formula fields stuff, you store the plain value in the db and the renderer is formatting it beautiful.

1 Like

That’s perfect thanks! I hadn’t realised the renderer could be applied to the datatable so that’s much nicer than having to create a bunch of formula fields and it also works with the existing aggregate formula fields.

1 Like