This is a migrated thread and some comments may be shown as answers.

Telerik RadGrid incorrectly remembering previous filter options

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justus
Top achievements
Rank 1
Justus asked on 03 Jun 2014, 07:27 PM
In my radgrad I am showing/hiding filter options depending on which filter is clicked on by utilizing the FilterMenuShowing client side function. The problem is it always remembers the last selection. So if in filter A I hide "IsNull", then "IsNull" will also be hidden when I click on Filter B after clicking Filter A. However, if I click Filter B first, "IsNull" is shown. Curiously, if I click Flilter A, then Filter B TWICE, then it works as expected. Why is it remembering the last set of filter options, and how can I fix this?

The following is my code: 

function filterMenuShowing(sender, eventArgs) {
                var menu = eventArgs.get_menu();
                var items = menu._itemData;
                var i = 0;
                while (i < items.length) {
                    var arrMenuOptions = ['GreaterThan', 'LessThan', 'IsEmpty', 'IsNull', 'NotIsEmpty', 'NotIsNull', 'GreaterThanOrEqualTo', 'LessThanOrEqualTo', 'Between', 'NotBetween'];
                    var filterOption = items[i].value;
                    if (arrMenuOptions.contains(filterOption)) {
                        var item = menu._findItemByValue(filterOption);
                        if (item) {
                            var columnName = eventArgs.get_column()._element.UniqueName;
                            
                            if (columnName == "JobNumber" && (filterOption == "GreaterThan" || filterOption == "LessThan")) {
                                item._element.style.display = "";
                            } else if ((columnName == "InitialDate" || columnName == "FinalDate") && (filterOption == "Between" || filterOption == "NotBetween" || filterOption == "IsNull" || filterOption == "NotIsNull" || filterOption == "IsEmpty")) {
                                item._element.style.display = "";
                            } else if ((columnName == "JobDescription" || columnName == "JobCategory" || columnName == "JobType") && (filterOption == "IsEmpty" || filterOption == "NotIsEmpty")) {
                                item._element.style.display = "";
                            } else {
                                item._element.style.display = "none";
                            }
                        }
                    }
                    i++;
                }
            }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Jun 2014, 06:59 AM
Hi Justus,

You can set the following code snippet to have your filter menu always selected to same option.

C#:
protected override void OnPreRender(EventArgs e)
{
  base.OnPreRender(e);
 //Access column
  GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("ColumnUniqueName");
 //Set the required FilterFunction
  column.CurrentFilterFunction = GridKnownFunction.EqualTo;
  RadGrid1.Rebind();
}

Thanks,
Princy
Tags
Grid
Asked by
Justus
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or