Hello DevEx team !
Have following problem:
the search in lookupviews is "case sensitive" and it's confused users.
How can i change it to "case insensitive" ?
PS. I use servermode in my project.
Thanks
JeyKey
How can I activate "case insensitive" search in lookup views ?
Answers
Hello JeyKey,
You can add the Upper or Lower functions to the filter to make it case-insensitive. For example:
C#public class ViewController1 : ViewController {
public ViewController1() {
TargetViewId = "DomainObject1_LookupListView";
}
protected override void OnActivated() {
base.OnActivated();
Frame.GetController<FilterController>().CustomBuildCriteria += new EventHandler<CustomBuildCriteriaEventArgs>(ViewController1_CustomBuildCriteria);
}
void ViewController1_CustomBuildCriteria(object sender, CustomBuildCriteriaEventArgs e) {
e.Criteria = CriteriaOperator.Parse("Contains(Upper(Name), ?)", e.SearchText.ToUpper());
e.Handled = true;
}
protected override void OnDeactivated() {
base.OnDeactivated();
Frame.GetController<FilterController>().CustomBuildCriteria -= new EventHandler<CustomBuildCriteriaEventArgs>(ViewController1_CustomBuildCriteria);
}
}
Please feel free to contact us if you have any difficulties.
Thanks,
Anatol
Hello JeyKey,
It appears that the Name property does not exist in the Meldung class, for which ListView is shown. I have provided ViewController1 just as an example. If you wish to use case-insensitive search in all list views, you need to generate the search criteria dynamically based on properties of the shown class. I believe that the root listview FilterByText include the collection propertys Support Center issue will be helpful.
Thanks,
Anatol
Hello Anatol,
thank you for advice. Have adapted to my needs, and it's work fine.
JeyKey
I have implemented a solution that automatically works with all the LookupListViews:
C#public class LookupListViewController : ViewController<ListView>
{
private static readonly string[] _possibleSearchFields = new string[] { "Name", "Description", "Text" };
protected override void OnActivated()
{
base.OnActivated();
if (View.Id.EndsWith("_LookupListView")) {
Frame.GetController<FilterController>().CustomBuildCriteria += ViewController1_CustomBuildCriteria;
}
}
// Implement case-insensitive search in DropDowns.
void ViewController1_CustomBuildCriteria(object sender, CustomBuildCriteriaEventArgs e)
{
List<IModelMember> members = View.Model.ModelClass.OwnMembers
.Where(m => m.Type == typeof(string))
.ToList();
foreach (string searchField in _possibleSearchFields) {
if (members.Any(m => m.Name == searchField)) {
CriteriaOperator op = new FunctionOperator(FunctionOperatorType.Upper, new OperandProperty(searchField));
string searchValue = String.Format("%{0}%", e.SearchText.ToUpperInvariant());
e.Criteria = new BinaryOperator(op, new OperandValue(searchValue), BinaryOperatorType.Like);
e.Handled = true;
return;
}
}
}
protected override void OnDeactivated()
{
base.OnDeactivated();
if (View.Id.EndsWith("_LookupListView")) {
Frame.GetController<FilterController>().CustomBuildCriteria -= ViewController1_CustomBuildCriteria;
}
}
}
"_possibleSearchFields" lists common property names that you have used in lookup entities. You may have to adapt this list.
Hello JeyKey,
It appears that you are using the case-sensitive collation in your database. Make it case-insensitive to achieve the desired behavior.
Thanks,
Anatol
Hello Anatol!
thanks for answer , but it's not a solution for me.
i can't change this in database global.
If it's possible to do it in DataStoreProvider, can you tell me how .
Thanks
JeyKey