How to Show/hide filter items based on user rights.

4 posts, 0 answers
  1. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 14 Mar 2013 Link to this post

    Folks, Using RadControls for ASP.NET AJAX Q1 2013 with VS 2010. I would like to conditionally hide certain filter items based on user rights. Example I have a session variable i.e. Session["UserRights"].

    If Session["UserRights"] == "Supervisor" then show all available filter items in a GridDateTimeColumn, if not then available filter items in that column will be No Filter & Equal To.

    Attached is my screen shot. Any help will be appreciated.

    Thanks

    gc_0620
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Mar 2013 Link to this post

    Hi,

    To limit the filter options displayed for a given column on the client, you need to intercept the OnFilterMenuShowingclient event of RadGrid/OnClientShown event of the filter menu and hide some of the possibles choices from within the body of the respective handler. Here is the sample code.
    aspx:
    <ClientSettings>
      <ClientEvents OnFilterMenuShowing="filterMenuShowing" /></ClientSettings>
    <FilterMenu OnClientShown="MenuShowing" />

    JS:
    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;
               menu.repaint();
           }
           function filterMenuShowing(sender, eventArgs) {
               column = eventArgs.get_column();
           }

    Thanks,
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 18 Mar 2013 Link to this post

    Hi Shinu,

    Thanks for your reply but I am sorry to say that we have a miscommunication here. The solution and the link is only reducing the filter items; my intention was to reduce the filter items based on user access rights not globally reduce the items.

    The workflow in my project is Login.aspx->Default.aspx. After Login.aspx, I am storing the users access rights (i.e. Supervisor or regular user) into session variable Session["UserRights"].

    In Default.aspx page load event, if value of Session["UserRights"] = 'Supervisor', show all available filter items of Telerik GridDateTimeColumn.  If not, available filter items of GridDateTimeColumn will be limit to No Filter & Equal To. That is my desired result.

    Thanks

    gc_0620





  5. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 21 Mar 2013 Link to this post

    Hello,

     You can also reduce the filter menu options conditionally on the server (for example in the RadGrid Init event or later if needed) as shown at the end of the help topic.
    There you can also check for the session variable and decide whether you need to hide the menu items or not. The filter menu is shared control among all columns so if you need to modify the filter options only for a particular column (and leave the default options for the other columns) then this has to be done on the client where you have access to the column for which the menu is currently invoked. If this is the case then you will also need to serialize a variable with the user rights on the client so that they are accessible in the MenuShowing event.

    I hope this helps.

    Kind regards,
    Marin
    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.
Back to Top