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

Modify grid filter menus from client side

1 Answer 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 22 Feb 2012, 07:06 PM
I need to modify the filter menus on the grid selectively by data type (and possibly even by specific data column).  There is some discussion of this on http://www.telerik.com/help/aspnet-ajax/grid-reducing-filtermenu-options.html , but there is no actual example of the client javascript shown.  I am successfully modifying the filter menus from the server side, so I understand the concepts, but I don't have the javascript code samples to understand the properties and values that I have access to on the client side.

Any simple examples that anyone might have would be immensely helpful.

Thanks in advance!

Lynn

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 27 Feb 2012, 12:00 PM
Hello,

The help topic you have pointed out has a JavaScript part that shows how to hide some of the filter options based on specific type. You need to click on the tab labeled JavaScript(check the attached image file).

Here is the code from the help topic:

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">         
var column = null;
function MenuShowing(sender, args) {
  if (column == null) return;
  var menu = sender; var items = menu.get_items();
  if (column.get_dataType() == "System.String") {
    var i = 0;
    while (i < items.get_count()) {
      if (!(items.getItem(i).get_value() in { 'NoFilter': '', 'Contains': '', 'NotIsEmpty': '', 'IsEmpty': '', 'NotEqualTo': '', 'EqualTo': '' })) {
        var item = items.getItem(i);
        if (item != null)
          item.set_visible(false);
      }
      else {
        var item = items.getItem(i);
        if (item != null)
          item.set_visible(true);
      } i++;
    }
  }
  if (column.get_dataType() == "System.Int64") {
    var j = 0; while (j < items.get_count()) {
      if (!(items.getItem(j).get_value() in { 'NoFilter': '', 'GreaterThan': '', 'LessThan': '', 'NotEqualTo': '', 'EqualTo': '' })) {
        var item = items.getItem(j); if (item != null)
          item.set_visible(false);
      }
      else { var item = items.getItem(j); if (item != null) item.set_visible(true); } j++;
    }
  }
  column = null;
}
function filterMenuShowing(sender, eventArgs) {
  column = eventArgs.get_column();
}
</telerik:RadCodeBlock>

Greetings,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Lynn
Top achievements
Rank 2
Answers by
Andrey
Telerik team
Share this question
or