ecLearn - Learning Management System built on top of Microsoft Dataverse for Power Platform and Dynamics 365 users

ENGINEERED CODE BLOG

Dynamics 365 Portal & SharePoint: Using CSS To Save Some Clicks

In a previous post, I asked you not to forget about CSS when customizing the user experience of some of the out-of-the-box features of the Dynamics 365 Portal product. In this post I’ll provide another example of using this technique to reduce the number of clicks required to remove a SharePoint document.

Consistency Can Be the Enemy of Simplicity

We all rejoiced when Microsoft added the out-of-the-box SharePoint integration back to the Dynamics 365 Portal product. For some technical reasons, the SharePoint integration wasn’t available when the product first moved from Adxstudio to Microsoft, but thankfully as part of the October ’18 release, it is now back.

I was using this integration in a project recently when the client asked me if I could make one of the user experiences a bit cleaner. Specifically, they wanted to know if it was possible to make the Delete button that appears within the row of a document appear directly in the table, without have to click the drop down arrow.

I knew that I could probably do this with JavaScript (because you can pretty much do anything with regards to the interface with JavaScript), however my goal was to try to do it using only CSS.

Now, it may seem like a bit of an odd user experience to have to click the drop down to get to the Delete button, and that’s because it is. But it’s not really intentional. It’s because Microsoft uses the same user interface elements across the Portal. What you’re seeing for the SharePoint documents is pretty much the same as you’d see for an Entity List. Reusing this code means less to maintain for Microsoft, and also means a consistent experience for users of the Portal – all generally good things. However, in this particular case, it means an extra unnecessary click, which my client wanted removed, especially since we aren’t leveraging this type of interface anywhere else on the project, so there wasn’t anything else that would make consistency important.

CSS to the Rescue!

I’m not going to rehash the reasons I like CSS in this post, but there is one particular reason in this case that using CSS makes our life a lot easier, and that’s due to the dynamics nature of the SharePoint documents table.

If we were to use JavaScript in a situation like this, that generally means we are manipulating the DOM, moving things around to get them to show up as we want. Often that is done when the page loads. However, the SharePoint documents table can be constantly changing – users can add and remove documents without the page refreshing. If we were to use JavaScript, we’d have to handle all of those events to make sure our Delete button is always consistent. It would be a pain.

Instead, since CSS is “always on”, we don’t have to worry about handling when the table changes – our CSS will automatically get applied.

Another reason we try to avoid manipulating the DOM is that if you don’t do it right, you can lose the events that are attached to the elements. For example, there is JavaScript code that run when the Delete button is clicked. If we start moving the button around, you can possibly lose that functionality. There’s no point removing clicks to get to a button if the button doesn’t work! Again, it’s possible to move the button and keep the events, it just another thing that makes it tricky.

Now, depending on how Microsoft had chosen to implement that functionality, a pure CSS option may not have been possible. If the Delete button had been added to the page in response to the click event on the drop down arrow, then we wouldn’t have anything to target with our CSS until the user clicked on the button. Thankfully, however, the Delete button is always on the page, just hidden until the user click the arrow to show it.

Since the markup for the button is always on the page (just hidden), we can get to where we want to go in two easy steps:

  1. Always hide the drop down arrow
  2. Always show the delete button

Using the browser developer tools allows us to find how to target both of these elements.

To hide the drop down arrow:

.sp-item .toolbar > a {
    display: none;
}

To always show the Delete button:

.sp-item .toolbar .dropdown-menu {
    display: block;
    position: relative;
    border: none;
    background: none;
    box-shadow: none;
    margin: 0;
    padding: 0;
}

You’ll notice I’ve added a few more styles in there to make the button fit in a bit better with the table.

Just add this CSS to your Web Page, or Web Template, and you’ll get:

With just a few lines of CSS, we’ve improved the user experience quite a bit by saving the user an unnecessary click!

As mentioned above, Entity Lists use similar markup – with just a few tweaks, you could apply the same technique to show the action buttons inline in the table. In fact, these drop down arrows are a standard Bootstrap feature used throughout the Portal, so there are probably quite a few different places you could do this if you wanted.

Bonus: Hiding the Modified Column

You may have noticed that in my screenshots, the Modified column wasn’t visible in the SharePoint documents table – this was another request from my client, as it was not important for the users to see. Again, CSS makes this very simple:

.sharepoint-data tr th:nth-child(2), .sharepoint-data tr td:nth-child(2) {
    display: none;
}

This CSS targets the second child of both the header row and the body rows of the table used to display SharePoint documents, and then simply hides them using display: none;.

It is important to note that the markup still exists on the page, meaning an advanced user can still find out what the dates are. So don’t use this technique to hide information you consider to be confidential.

Double Bonus: Hiding the New Folder Button

Another request was to hide the button that allows the user to create a new folder. This simple CSS accomplishes that task:

.add-folder {
    display: none;
}

Again, an advanced user could easily unhide the button using developer tools, so this is about user experience, not security.

13 responses to “Dynamics 365 Portal & SharePoint: Using CSS To Save Some Clicks”

  1. […] for using CSS to customize the user experience for a Dynamics 365 Portal, as expressed in my last post, unfortunately CSS can’t do everything. Continuing on with the theme of the Dynamics 365 […]

  2. Elie Mouawad says:

    In my current version 05/02/2020 the suggested solution wouldn’t work but this helped me find a solution myself:

    /* Removes the dropdown for the subgrid */
    .btn.btn-default.btn-xs {
    display: none;
    }

    /* Displays the buttons that were in the dropdown inline inside the row */
    .dropdown-menu {
    display: flex;
    position: relative !important;
    top: 100% !important;
    left: 0 !important;
    border: none;
    background: none;
    box-shadow: none;
    margin: 0;
    padding: 0;
    }

  3. Elie Mouawad says:

    Actually, we need to change
    .dropdown-menu {

    to

    .btn.btn-default.btn-xs ~ ul {

    as the previous way apparently had more uses than expected and broke the style a bit on the portal, this seems to work fine for now at least! But even if it doesn’t 100% hope it helps somebody trying to fix theirs to show them the way.

  4. Brilliant, Works a treat, I am trying to a similar thing on a entity list to hide the button and have the view details text in line, thus saving me a click,.

    . dropdown action btn btn-default btn-xs
    {
    display:none;
    }

    however the view details seems more difficult to grab, as it position is fixed, Any Ideas, thanks in advance

    • Nicholas Hayduk says:

      You just need to override their position:fixed with your own position:relative, and use !important. Something like:

      .dropdown.action .btn.btn-default.btn-xs {
      display:none;
      }

      .entitylist .dropdown-menu {
      display: block;
      position: relative;
      border: none;
      background: none;
      box-shadow: none;
      margin: 0;
      padding: 0;
      }

      Nick

  5. Syed says:

    Hi Nicholas,

    Thanks for the article. One question: do you know if there’s a way to show customized the view that appears on the Documents Subgrid on the Portal? I need to show a number of columns in addition to Name and Modified. Choosing a custom view for the documents sub grid on Dynamics form has no impact on the subgrid that gets rendered on the portal . It always shows just these two columns.

    • Nicholas Hayduk says:

      Unfortunately no – as far as I know there is no way to customize the columns you see there. The only thing we’ve done is use CSS to hide columns if there are some you don’t want.

      Nick

  6. Syed says:

    I need to achieve this for a normal (not document related) grid that’s placed on a webform. Where do I need to place the modified version of the css? I tried to do it on the web page (under Advanced -> Custom CSS) that contains the web form but doesn’t take into effect.

    • Nicholas Hayduk says:

      Hmm, I would’ve thought adding it to the Custom CSS of the web page that the web form is on would work. Did you make sure to clear the cache after you did that?

      Nick

  7. NG says:

    Hi Nick,
    Thank you for tips you are sharing on how to customize UI via CSS.
    Could you please help me to solve one.
    I have a required filed, on webform of portal.
    I need to change color of “*” or remove it from the label.
    Do you have any idea of how could it be done.
    Thank you.
    NG
    More info:

    First Name
    ::after
    *
    *

    • Nicholas Hayduk says:

      Something like this should work:

      #firstname_label::after {
      color: green !important;
      }

      #firstname_label::after {
      display: none;
      }

      Nick

  8. Hardik says:

    Is there any way to hide/show Delete Button in SharePoint Document Location Subgrid based on conditions?

    • Nicholas Hayduk says:

      My approach for this would be to use Liquid to check the conditions, and if you want it hidden, the Liquid outputs JavaScript that adds a CSS style that hides the delete button.

      Nick

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact

Engineered Code is a web application development firm and Microsoft Partner specializing in web portals backed by Dynamics 365 & Power Platform. Led by a professional engineer, our team of technology experts are based in Regina, Saskatchewan, Canada.