.Nice formating kills column sorting

This is frequently encountered and a bit of a shortcoming in form scaffolding currently. There’s been discussion about improving this though. For now you can try using raw values:

private static $summary_fields = array (
	'PricePerNight' => 'Price',
	'FeaturedOnHomepage' => 'Featured?'
);

Then modifying their formatting directly in the gridfield. Unfortunately this means you need to manually update any corresponding gridfield instances you have explicitly created, as well as any that are automatically generated (scaffolded) for your data model, e.g. in ModelAdmin interfaces.

// Make gridfield values nice to read while preserving sorting
$columns = $config->getComponentByType('GridFieldDataColumns');
$columns->setFieldCasting(array(
	'PricePerNight' => 'Currency->Nice',
	'FeaturedOnHomepage' => 'Boolean->Nice',
));
1 Like