Creating Custom Header

CopyC#
  public class CustomHeaderExample : SettingsHeadersWrapperBase
    {
      //Property name specfies what the property is called on the object.  This is not enforced though.
      //You may call it whatever you want.  The main use of this field is specify a Unique Identifier
    public override string PropertyName
    {
        get { return "CanCreateFolio"; }
    }

        //This is the name that is displayed to the user.
    public override string FriendlyName
    {
        get
        {
            return "Can Create Folio";
        }
    }

        //This displays the search values this header uses in the advanced search menu.
    public override List<ISearchHeader> GetPossibleSearchValues(ISiteManager siteManager)
    {
        //It is recommended that you use this method to get all of the predefined Search Options.
        return SearchUtilites.GetSearchInfosByType(DisplayTypes.Boolean);
    }

        //Tests whether x satisfies the search given
    public override bool SatisfiesSearch(ICartellaObject x, ISearchHeader searchInfo, string searchValue, IFolio folio)
    {
        IUser user = x as IUser;
        if (user == null)
        {
            throw new ArgumentException("x must be of type IUser");
        }

        //Make sure that the search expects a boolean
        if (searchInfo.DisplayInfo.Type == DisplayTypes.Boolean)
        {
            //This is the recommended way to perform a search.
            //Of course you could do whatever you wanted here
            return searchInfo.Search(user.CanCreateFolio, searchValue);
        }
        else
        {
            //return a fail safe value
            return false;
        }
    }

    //This displays which setting this header can be used for
    public override SettingsTypes SettingType
    {
        get { return SettingsTypes.User; }
    }

    //This is the comparer function which compares two different Cartella objects.
    //This controls the sort for the grid.  It returns 1 if they are greater, 0 if equal, and -1 if less than.
    public override int Compare(ICartellaObject x, ICartellaObject y, IFolio folio)
    {
        //THis function just compares the display values that are on the grid. 
        return base.StringCompareDisplayName(x, y);
    }

            public override bool CanSort
    {
        get
        {
            return true;
        }
    }

    //Allows clinet side filtering for these headers items
    public override bool CanDoClientSideFilter
    {
        get
        {
            return true;
        }
    }

    //Does not use external template. I will explain later how to use this.
    public override bool NeedExternalTemplate
    {
        get
        {
            return false;
        }
    }

    //Whether this header can be used right now
    public override bool CanBeUsed(SettingsViewType viewType, IFolio folio)
    {
        return true;
    }

        //This gets the value that will be displayed in the grid.
    public override string GetDisplayValue(ICartellaObject x, IFolio folio)
    {
        IUser user = x as IUser;
        if (user == null)
        {
            throw new ArgumentException("x must be of type IUser");
        }

        return user.CanCreateFolio ? "Yes" : "No";
    }
}
Note

The above code example contains a fully functional admin header.

Important

It is important to note that many of the functions have an override that takes a folio as well. It is recommened that when overriding a method you over ride the function with the folio parameter, as the other one will call it with the same parameters and null in the folio parameter. This is to specify whether we are in local (in a folio) or global (settigns accesible without a folio) settings.

PropertyName

This name is used as a unique idenitifer for the header and must be unique across all headers for it to work properly.

FriendlyName

This is the name displayed to users.

GetPossibleSearchValues

This method gives all of the advanced search options that can be run agaisnt this header. There are some helper methods in the static class SearchUtilites that make this easier. These should meet most needs.

Tip

You can also define your own advanced search options. Go Create Custom Search Option for tips on how to do this.

SatisfiesSearch

This returns whether the given object satisfies the search given by the searchInfo paramater with the search value given by the searchValue paramaeter.

It is recommended that you use the searchInfo.Search to do this search.

SettingType

This returns the object type that this header is displayed for.

Compare

This function takes two Cartella Objects and compares them. It returns an integer in accordance to the ususal compare. An integer greater than 0 if x is greater, an integer less than 0 if y is greater, and 0 if they are equal.

Tip

There a couple of predefined compares that can be used for some common tasks.

  • StringCompareDisplayName is defined on the base class. It does a string compare on the value returned from GetDisplayValue .

  • CompareDateTime compares two cartella objects based on data information pulled from the field given by the filedName parameter.

CanSort

Returns a boolean specifing whether it can be sorted by this header on the client side. If this returns true you should override the compare function. If it returns false, the compare function need not be overrode since it will never be callled.

CanDoClientSideFilter

Returns a boolean specifing wheter this header can be used for client side filtering.

NeedExternalTemplate

This returns a boolean of whether an external template is needed for this header. An external template can be used to insert HTML into the grid. If true is returned then the ExternalTemplate method must be specified. More will be explained in the advanced section.

CanBeUsed

This returns true if the given header can be used right now. An example fo something this could be used for is to specify whether this can only be displayed in the deleted view.

GetDisplayValue

Specfies the string that will be displayed to the user in the grid reflecting the display value.