Adding custom UniGrid transformations

The UniGrid provides built-in transformations for easy formatting of the content of columns. To learn about the UniGrid transformations that are available by default, see the description of the externalsourcename column attribute in Reference - UniGrid definition.

If you need to display column values in a custom format, you can register your own UniGrid transformations:

  1. Open your project in Visual Studio.

  2. Create a class file in the App_Code folder (orĀ CMSApp_AppCode -> Old_App_Code on web application projects).

  3. Extend the CMSModuleLoader partial class.

  4. Create a new class inside CMSModuleLoader that inherits from CMSLoaderAttribute.

  5. Add the attribute defined by the internal class before the definition of the CMSModuleLoader partial class.

  6. Override the Init method inside the attribute class and register your UniGrid transformations.

    • Call the UniGridTransformations.Global.RegisterTransformation method for each transformation.
  7. Implement the methods that define the functionality of your custom UniGrid transformations.


using CMS.Base;
using CMS.UIControls;
using CMS.Helpers;
using CMS.PortalEngine;

public partial class CMSModuleLoader
    /// <summary>
    /// Attribute class that ensures the loading of custom UniGrid transformations.
    /// </summary>
    private class CustomUniGridTransformationsAttribute : CMSLoaderAttribute
        /// <summary>
        /// The system executes the Init method of the CMSModuleLoader attributes when the application starts.
        /// </summary>
        public override void Init()
            // Registers the #customBoldText UniGrid transformation
            UniGridTransformations.Global.RegisterTransformation("#customBoldText", CustomBoldText);

            // Registers the #isStyleSheetCheckedOut UniGrid transformation
            UniGridTransformations.Global.RegisterTransformation("#isStyleSheetCheckedOut", IsStyleSheetCheckedOut);

        // Method that defines the #customBoldText UniGrid transformation
        // Wraps the UniGrid column text value into a <strong> element
        private static object CustomBoldText(object parameter)
            return "<strong>" + ValidationHelper.GetString(parameter, "") + "</strong>";

        // Method that defines the #isCheckedOut UniGrid transformation
        // Indicates whether the specified stylesheet object is currently checked out for editing
        private static object IsStyleSheetCheckedOut(object parameter)
            // Gets the stylesheet object based on the ID in the parameter
            CssStylesheetInfo stylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo(ValidationHelper.GetInteger(parameter, 0));

            // Evaluates whether the stylesheet is checked out
            if ((stylesheet != null) && stylesheet.Generalized.IsCheckedOut)
                return "<span class=\"StatusEnabled\">" + ResHelper.GetString("general.yes") + "</span>";

            return "<span class=\"StatusDisabled\">" + ResHelper.GetString("") + "</span>";

Once a UniGrid transformation is registered, you can use it in the externalsourcename attribute of UniGrid columns.



    <ug:Column Source="UserName" Caption="$general.username$" Width="100%" ExternalSourceName="#customBoldText" />



    <column source="StylesheetID" caption="Checked out" wrap="false" externalsourcename="#isStyleSheetCheckedOut" />