When we have a requirement to remove sub-grid buttons, there are two supported ways to do that.
Ref : http://missdynamicscrm.blogspot.com/2015/11/hide-add-existing-button-or-plus-button-subgrid-crm.html
- Hide through Security Role (which in most cases this is not possible)
- Hide using Ribbon Workbench (this did not worked for me and many developers had face the same issue.)
function hideAddRemoveButtonSubgrid() { try { // Hide add/remove buttons addEventToGridRefresh(setAddButtonDisplayNone); } catch (e) { } } var gridId = "grid_components"; function setAddButtonDisplayNone() { // Hide Add Button var addImage = document.getElementById(gridId + "_addImageButton"); if (addImage) { addImage.style.display = 'none'; } // Hide delete buttons var cont = true; var i = 0; while (cont) { var deleteButtionId = "gridBodyTable_gridDelBtn_" + i; var deleteButtion = document.getElementById(deleteButtionId); if (deleteButtion) { deleteButtion.style.display = 'none'; } else { cont = false; } i++; } } function addEventToGridRefresh(functionToCall) { // retrieve the subgrid var grid = document.getElementById(gridId); // if the subgrid still not available we try again after 1 second if (grid == null) { setTimeout(function () { addEventToGridRefresh(functionToCall); }, 1000); return; } // add the function to the onRefresh event grid.control.add_onRefresh(functionToCall); var addImage = document.getElementById(gridId + "_addImageButton"); if (addImage) { if (addImage.style.display.toLowerCase() == "block") { setAddButtonDisplayNone(); } } }
And finally add a page event handler to call the method "hideAddRemoveButtonSubgrid" in page load event.
This hide the add button for the given grid, and will hide all the delete buttons in all the grids in the page.
Ref : http://missdynamicscrm.blogspot.com/2015/11/hide-add-existing-button-or-plus-button-subgrid-crm.html
No comments:
Post a Comment