As an app author, you may want to make some records editable but others non-editable, based on criteria. In this tech tip, we show you how to hide the “edit” option where not needed. We are using an example of a Tabular Report DataPage.
The following screen shows a report where the edit option is conditionally hidden for some records.

Image showing records with disabled inline edit.
Steps:

  1. Create or edit a Tabular Report.
  2. On the Search and Report Wizard - Configure Results Page Fields screen, click the Insert button in the bottom right corner of the DataPage Elements panel and add Header & Footer.
  3. In the header, disable the HTML editor and paste the following code:

    Custom code for conditional edit option.
  4. In the bottom right corner of the DataPage Elements panel, click the Insert button and add a Calculated field. Move it to the first position, above other elements.
  5. In the calculated field, paste the following SQL formula that compares specific field values with the set condition and returns a 'hide' or 'dont_hide' result:CASE
    WHEN <your_SQL_condition>
       THEN 'hide'
    ELSE 'dont_hide'
    END

    Replace <your_SQL_condition> with a relevant condition.

    Example:
    CASE
    WHEN [@field:Status]= 'Completed'
    THEN 'hide'
    ELSE 'dont_hide'
    END

    Custom code for the conditional editing option.

  6. In the footer of your DataPage, paste the following JavaScript code:

    Custom code for the conditional edit option.
  7. You can also use the above code for inline delete or hiding view details. To do that, replace InlineEdit with InlineDelete or DetailsLink.

Note: This article uses external HTML, JavaScript, or third-party solutions to add functionality outside of Caspio Bridge’s standard feature set. These solutions are provided “as is” without warranty, support, or guarantee. The code within this article is provided as a sample to assist you in the customization of your web applications. You may need a basic understanding of HTML and JavaScript to implement successfully. 

For assistance with further customization based on your specific application requirements, please contact our Professional Services team. 

code1
<style>
th.cbResultSetLabel:nth-child(1), td.cbResultSetData:nth-child(1) {
display: none;
}
</style>
code2
<script>
if (typeof hideEdit == 'undefined') {
const calculatedFieldPosition = 1
const hideEdit = () => {
document.querySelectorAll(`td:nth-child(${calculatedFieldPosition})`).forEach( cell =>{
if (cell.innerText.toLowerCase() == 'hide') {
cell.parentElement.querySelectorAll('[data-cb-name="InlineEdit"]').forEach(edit=>{edit.style.display = 'none'})}
})}
const addObserver = () => {
new MutationObserver(mutations=>{
for (let i=0; i< mutations.length; i++) {
let addedNode = mutations[i].addedNodes[0]
if (addedNode !=null && addedNode instanceof HTMLElement) {
  if (addedNode.classList !=null) {
     if(addedNode.classList.contains('cbResultSetActionsLinks')) {
    hideEdit ()
    break
    }
}}
}
}).observe(document.querySelector('body'), {childList: true, subtree:true})
}
hideEdit ()
addObserver ()
}
</script>