Ticket T342565
Visible to All Users

How to prevent user from using non-persistent properties in FilterEditor when ServerMode is enabled?

created 9 years ago

In my persistent class I define non-persistent collection like this:

C#
[NonCloneable] public XPCollection<TechnologyServicingEvent> TechnologyServicingEvents { get { XPCollection<TechnologyServicingEvent> result = new XPCollection<TechnologyServicingEvent>(Session); result.Criteria = CriteriaOperator.Parse(string.Concat("[TechnologyServicingReports][[Technology.Id] = {", Id.ToString(), "}]")); return result; } }

However, once this persistent class is used in ListView with ServerMode enabled, and user add this property in filter expression, it results in exception:

Cannot query a data store using the "[TechnologyServicingEvents][] And [TechnologyModel.TechnologyType.TechnologyClass!] = ##XpoObject#ELVAC.TechIS.Model.TechnologyManagement.TechnologyClass({b9dbf961-ced1-4f25-becf-fca55426b7c1})#" criterion because it uses the 'TechnologyServicingEvents' nonpersistent property

Is there any way how to hide non-persistent properties from FilterEditor in ServerMode and disable all the filtering features in such a case?

Answers approved by DevExpress Support

created 9 years ago

Hello Svatopluk,

You can hide a certain property from the UI using the [Browsable(false)] attribute. If you want to hide it only in the filter control, handle the GridView.FilterEditorCreated event as shown below:

C#
public class ViewController1 : ObjectViewController<ListView, Payment> { GridListEditor gridListEditor; protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); gridListEditor = View.Editor as GridListEditor; if (gridListEditor != null) { gridListEditor.GridView.FilterEditorCreated += GridView_FilterEditorCreated; } } void GridView_FilterEditorCreated(object sender, DevExpress.XtraGrid.Views.Base.FilterControlEventArgs e) { FilterEditorControl filterControl = e.FilterBuilder.FilterControl as FilterEditorControl; if (filterControl != null) { filterControl.FilterColumns.Remove(filterControl.FilterColumns["TechnologyServicingEvents"]); } } protected override void OnDeactivated() { if (gridListEditor != null) { gridListEditor.GridView.FilterEditorCreated -= GridView_FilterEditorCreated; gridListEditor = null; } base.OnDeactivated(); } }

Let me know if you need further assistance.

    Show previous comments (9)
    Anatol (DevExpress) 9 years ago

      To disable the capability to filter the ASP.NET grid control by non-persistent properties, iterate through the ASPxGridListEditor's columns and set their GridViewColumn.Settings.ShowInFilterControl, ridViewColumn.Settings.AllowAutoFilter and GridViewColumn.Settings.AllowHeaderFilter properties to DefaultBoolean.False. Please let me know if you need further assistance with this task.

        Perfect, thank you.  For future reference, here's an example.

        C#
        public class WebPersonListViewCustomizationController : ObjectViewController<ListView, Person> { protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); var gridListEditor = View.Editor as ASPxGridListEditor; if (gridListEditor != null) { foreach (var gleColumn in gridListEditor.Columns.OfType<ASPxGridViewColumnWrapper>()) { if (IsNonPersistentProperty(gleColumn.PropertyName)) { DisableFilteringOnColumn(gleColumn); } } } } void DisableFilteringOnColumn(ASPxGridViewColumnWrapper column) { column.Column.Settings.AllowAutoFilter = DefaultBoolean.False; column.Column.Settings.AllowHeaderFilter = DefaultBoolean.False; column.Column.Settings.ShowInFilterControl = DefaultBoolean.False; } bool IsNonPersistentProperty(string propertyName) { switch (propertyName) { case "PropertyCreatedAtRuntime": case "NonPersistentProperty": return true; default: return false; } } }
        Anatol (DevExpress) 9 years ago

          Thank you for sharing your code. You can also obtain the member info by passing the column's PropertyName to the View.ObjectTypeInfo.FindMember method and check the IMemberInfo.IsPersistent property.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.