Skip to content

Grid LookupFilteringAttribute [Columns]

Victor Tomaili edited this page May 3, 2021 · 1 revision

[namespace: Serenity.Data.ComponentModel] - [assembly: Serenity.Core]

This attribute can be used to change a basic matching for filtering. It affects both QuickFilter or the Edit Filter extension. It is still based on a LookupScriptAttribute or on a Custom RowLookupScript. It is useful when you don't need a LookupEditor in your form or if it is a dynamically Custom LookupScript based on an editable string field you want to filter. Actually, you'll be good just using LookupEditorAttribute, if you don't use the IdField Property from LookupFiltering. So, this is not so useful as LookupEditor already covers it.

Attribute definition:

public partial class LookupFilteringAttribute : CustomFilteringAttribute
    {
        public LookupFilteringAttribute(string lookupKey)
            : base("Lookup")
        {
            SetOption("lookupKey", lookupKey);
        }

        public LookupFilteringAttribute(Type lookupType)
            : base("Lookup")
        {
            var attr = lookupType.GetCustomAttribute<LookupScriptAttribute>(false);
            if (attr == null)
                throw new ArgumentOutOfRangeException("lookupType");

            SetOption("lookupKey", attr.Key);
        }

        public String IdField
        {
            get { return GetOption<String>("idField"); }
            set { SetOption("idField", value); }
        }
    }

Usage: Without using the property IdField, it behaves just like LookupEditorAttribute would for filtering. The IdField will match the field you provided from your current row to the selected value from the LookupEditor, by adding an equality or a criteria, depending on the filter.

If not provided, IdField defaults to the current field.

        [...]
        [DisplayName("Country"), Size(15), LookupFiltering("Northwind.CustomerCountry")]
        public String Country
        {
            get { return Fields.Country[this]; }
            set { Fields.Country[this] = value; }
        }
        [...]

You can see the results as in:

QuickFilters (Note: You still need to write the QuickFilter Attribute to enable quickfiltering for the field)

Filters

Data From a StringEditor

Example of usage in CustomerRow.cs and a [Custom LookupScript Sample] (https://github.com/volkanceylan/Serene/blob/master/Serene/Serene.Web/Modules/Northwind/Customer/CustomerCountryLookup.cs)

Also see: Customize RowLookupScript

Clone this wiki locally