Jump to content

Hide bulk edit based on user logged in


Recommended Posts

Hi everyone, I was wondering if it is possible to hide the bulk edit option in a tabular page depending on the currently logged in user. For example, if the user logged in is an "employee", the option to bulk edit is hidden. If they are an "admin", it is shown. I can't seem to find any option to do this in Caspio but maybe some of you has experience with it.

Thanks!!

Link to comment
Share on other sites

Hi @ParkLoey,

You can use the following JavaScript on the Footer of your DataPage:

 

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
 if("[@authfield:Role]" ==  "Employee"){
           var elems= document.querySelectorAll(".cbResultSetCheckBoxCell");

[].forEach.call(elems, function(elem, i) {
elem.remove();

});

var checkboxheader = document.querySelector(".cbResultSetHeaderCheckBoxCell")

var bulkedit = document.querySelector("[id*='PageActionsCtnr']")

checkboxheader.remove();
bulkedit.remove();

}
});
</script>

 

make sure to change the Role in [@authfield:Role] with your actual role field, and Employee with the role type you want to hide the Bulk Edit option for.

Link to comment
Share on other sites

Hi @ParkLoey - you can also use this script in the Footer of the DataPage:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
 
if("[@authfield:Role]" == "Employee"){ 

document.querySelector("nav[class*='cbActionPanel']").style.display='none'; // Hide Edit button

let label  = document.querySelector('table[data-cb-name="cbTable"] th:nth-of-type(1)'); // Select the label of first column for checkboxes
let values  = document.querySelectorAll('table[data-cb-name="cbTable"] td:nth-of-type(1)'); // Select all the values in the first column for checkboxes
  
       /* Removing the selected fields */
       label.parentElement.removeChild(label)
       values.forEach(el => {
             el.parentElement.removeChild(el)
       });

} 

});
</script>

You can check these forum posts for reference:

 

Link to comment
Share on other sites

Hi @ParkLoey,

if you have the data grouping enabled but still want to hide the checkboxes conditionally based on user role, you can use the following:

 

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
 if("[@authfield:Role]" ==  "Employee"){
           var elems= document.querySelectorAll("input[type='checkbox']");

[].forEach.call(elems, function(elem, i) {
elem.style.display = "none"

});

var checkboxheader = document.querySelector(".cbResultSetHeaderCheckBoxCell")

var bulkedit = document.querySelector("[id*='PageActionsCtnr']")

bulkedit.style.display = "none"

}
});
</script>

Link to comment
Share on other sites

  • 4 weeks later...
  • 8 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...