Monday, December 17, 2018

SharePoint Online: How to add multiple class names to SPFx web part

If you had override the CSS using Content editor web part on Classic experience then you would have faced big problem in SPFx.

Yes, you cannot override the CSS design because CSS preprocessor adds some random characters at the end dynamically. So you cannot override.
You might think why do I need to provide design customization for users in SPFx.

Here is my requirement:
I want to build a web part that displays restricted port numbers in table format. It will have regular table structure with header and body. Something like below.

Restricted Ports
80
12345
Site owners can add this web part on their team site if they want. They might have different color themes applied. If they want to change the header's background to red then we cannot go and develop a web part for their team site. Instead we can provide a multi line text box on property pane and allow users to add their design customization. (Note: You will have to add )

Believe me, my users are very technical and they know how to play with CSS designs. 

Here's how to add multiple class names; 
<div className={[styles.panelStyle,'customclass'].join(' ')}>

Earlier it was like this;
<div className={styles.panelStyle}>

Hope you find it useful.

Happy coding !!!!!

Wednesday, August 22, 2018

SharePoint Online: Content search web part is not displaying all refinable values

Have you ever be in this situation where you do not see all refinable values under mapped refinable property in CSWP?
You are not alone. :)

Here's what happened;
Business requirement:
- Want to display particular department items

Solution:
- Use CSWP and configure the refiners section.

Implementation:
- I have a created a custom column to hold department values
- Mapped this custom column to a refinablestring for using it on Content search web part (CSWP)
- I created a page with CSWP and configured it. I could not see all the values under that refinablestring.

You can follow this step to check on the refinablestring values.
- Create a page with Search web parts (Search box, search results, refinement)
- Configure the refinement web part and add the same refinablestring. You will be able to see all values.
This way you can confirm that the refinablestring has all values.

Below table represents my issue.
CSWPSearch Refinement WP


Why CSWP is behaving differently?
Those refiner values are being displayed based on the Search results preview items. Thus we see limited values.


What did I do to view required department value?
Please remember, this does not display all the values in CSWP refiner section.

- On Basics tab, change the path that has items with required column value.
Eg: I want to add "Legal" under Refiners tab in CSWP. I know there is a site(https://<sitecoll>/Legalsubsite) with an item with "Legal" value.
- Goto Refiners tab and look for the required value under refinablestring. (Notice that the search result preview will be refreshed)
- Then add that value
- Go back to Basics tab and change the path to original i.e., https://<sitecoll>
- Click Ok.

Basically, we are narrowing down the search results on preview to see our refinable values.

That's it !!!!!
Hope you find this content useful.




Thursday, July 12, 2018

Generate Delve link dynamically using User's Email ID

Have you ever wondered to have a link on user name that navigates to their Delve page?
Well there's a solution. It works on SharePoint Online.

Requirement: A SharePoint page in SharePoint Online that displays lists users of the current site with their permission levels. End user should have the ability to view the user's Delve page.

Solution: Delve has several Query string properties.
                https://delve.office.com/?<properties>
       
                u = user id
                v = delve sections (eg: v=work or v=profiledetails)
                p = email id

By default, when you navigate to Delve page, it uses the parameter "u". I feel it is bit difficult to fetch user ID (guid) than email ID. Therefore we can use the parameter "p".

Note: You cannot use full email address. It should be user's login name.

Let us assume the user from xyz organization.

User: John doe
Login name: jdoe@xyz.com
Full email: John.Doe@xyz.com

Then the Delve url for John would be
https://delve.office.com/?p=jdoe@xyz.com&v=work


https://delve.office.com/?p=<user's login name>&v=work

Hope you find it useful ! :)