Change which Filter Menu Items are displayed based on source matching or user

Filter Menus and User Roles

I am looking for some way to change which Filters Menus displayed on a given page based on either some of the source criteria or the one of the connected users fields.

I have a filter menu which users love and it looks great. However the menu items is not the same depending on the users affiliated organization. What filter menu items a user sees needs to based on either the source or one of the user fields.

I have a decent size app with several different organizations using it. Recreating these pages for each organization wont work because then I get into to duplicates in main menu items as they all users are just that. So I need to change the filter menu based in one of the user fields or the source.

Any suggestions or code or other tricks is greatly appreciated.

Hi Tim,

Have you explored Page Rules to show/hide menu views for a “Value” (such as affiliated organization)? Page Rules - Knack Knowledge Base

Note: This can be quite unwieldy if you have dozens of organizations rather than “several.” Otherwise, unique “portals” (login pages) designed for the org is prob the only other option.

Hi Steve,

Unfortunately hiding views does not include the ability to hide filter menus. However I do appreciate the feedback. I hoping maybe somebody has some code that will do the trick. Thank you!!

Hi Tim

Just had a bit of a play and think I have the solution for you:

// view 15 is a view in which you want to hide a filter menu button dependent on user role...
$(document).on('knack-view-render.view_15', function(event, view, data) {
// check if Admin user role and hide 3rd filter menu button if not
  if (Knack.getUserRoles('object_7')!=true) { // check if Admin user role
    $("div.kn-records-nav > div > ul > li:nth-child(3)").hide();
  }
});

The thing you have to find out is what the “object key” is for the user role you want to use in your code - this is found easily by using the Inspect element feature in your browser when right clicking on the User Role you want to find it for (assuming you have developer mode for the browser turned on):

In this case you can see that Admin is “object_7”.

Hope this helps!!

Hi Julian,

I love the code and finding the view and the object key are no problem. It works great!! So my only question if I want to hide more then one button do I duplicate the code or can I add more then one filter button number? Thank you so much for your help my coding skills are not the greatest.

Hi Julian,

I just repeat the last line and it works great. So like below.

$("div.kn-records-nav > div > ul > li:nth-child(1)").hide();
$("div.kn-records-nav > div > ul > li:nth-child(3)").hide();

But I really I need to figure out how to limit it in that based on a specific field in that User Role when that field = XXXX. So in my case table-cell-field_489=xxxx

UPDATE - So something like this maybe.

// view 15 is a view in which you want to hide a filter menu button dependent on user role…

$(document).on(‘knack-view-render.view_894’, function(event, view, data) {

// check if Admin user role and hide 3rd filter menu button if not

if (Knack.getUserRoles(‘object_1’)!=true) { // check if Admin user role
if ($(“table-cell-field_489”).val()!= “MCT204”)

$("div.kn-records-nav > div > ul > li:nth-child(1)").hide();
$("div.kn-records-nav > div > ul > li:nth-child(2)").hide();
$("div.kn-records-nav > div > ul > li:nth-child(3)").hide();

}

});

Hi Julian,

I was mistaken it wasn’t working correctly. So I went back to your original code. On further review the code is when using object_1 which is Accounts or all users it works fine. But lets say I change it to object_2 which is users called Agents and then login with an Agent User it doesn’t hide any of the the specified fields. Still working with it though.

So here is the way you can do it based on any different user roles in my example I check for 2 different roles. For me though I still need to figure it out using a table field within the Account record.

// view 894 is a view in which you want to hide a filter menu button dependent on user role…

$(document).on(‘knack-view-render.view_894’, function(event, view, data) {

// check if User has the below role if so hide those filters

if (Knack.getUserRoles().includes(“object_19”)) { // check to see if user roles include

$("div.kn-records-nav > div > ul > li:nth-child(1)").hide();
$("div.kn-records-nav > div > ul > li:nth-child(2)").hide();
$("div.kn-records-nav > div > ul > li:nth-child(3)").hide();

}

});

// view 894 is a view in which you want to hide a filter menu button dependent on user role…

$(document).on(‘knack-view-render.view_894’, function(event, view, data) {

// check if User has the below role if so hide those filters

if (Knack.getUserRoles().includes(“object_54”)) { // check to see if user roles include

$("div.kn-records-nav > div > ul > li:nth-child(1)").hide();
$("div.kn-records-nav > div > ul > li:nth-child(4)").hide();
$("div.kn-records-nav > div > ul > li:nth-child(5)").hide();

}

});

Thank you JULIAN and TIM. It works great for me in the VIEW filter tabs.
Similarly I tried to hide MENU tabs using this code but not working. I must be missing something!