Generating the String of Filtered Columns on the XamDataGrid

I did this as an extension method to be able to use it everywhere I was using the XamDataGrid:


public static string GetFilterString(this XamDataGrid grid) {
    var filters = new List();
    foreach (var fieldLayout in grid.FieldLayouts) {
    foreach (var filter1 in (from filter in fieldLayout.RecordFilters where filter.Conditions.Count > 0 select filter)) {
        if (filter1.Conditions.Count > 1) {
                var conditionOperator = Enum.GetName(filter1.Conditions.LogicalOperator.GetType(), filter1.Conditions.LogicalOperator);
                var multiCondition = filter1.Field.Label + " " + string.Join(" " + conditionOperator + " ", filter1.Conditions);
                filters.Add("(" + multiCondition + ")");
                } else {
                    filters.Add(string.Format("{0} {1}", filter1.Field.Label, filter1.Conditions[0]));
                }
        }
    }
    return filters.Count > 0 ? "Current filters: " + string.Join(" And ", filters) : "Current filters: None";
}

So, now I can implement (in the code-behind) like this:


    myGrid.RecordFilterChanged += (sender, args) => { myLabel.Content = myGrid.GetFilterString();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s