2

A Person column, with no column formatting, has the desired functionality.

I.e. when you hover over a person's name, you can see their Person card etc.

So the starting state of the column formatting is:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json"
}

Then I add additional column formatting, with an if condition.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if([$Current_x0020_Assignment] =='', 'Not assigned', [$Current_x0020_Assignment.title])"
}

The logic above is saying:

When the value of the Current Assignment column is blank, add the text Not assigned,
otherwise, show the the Person's name.

What happens is that the text displays correctly, but I lose the 'hover' functionality that displays the Person card etc.

If I try referencing @currentField:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if([$Current_x0020_Assignment] =='', 'Not assigned', @currentField)"
}

or [$Current_x0020_Assignment]:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if([$Current_x0020_Assignment] =='', 'Not assigned', [$Current_x0020_Assignment])"
}

The Person column just displays [Object Object].

Is there a way to apply the desired conditional logic whilst retaining the hover functionality when hovering over the Person's name?

1 Answer 1

2

Per this answer, just defining the defaultHoverField property seems to work, ie:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if([$Current_x0020_Assignment] =='', 'Not assigned', [$Current_x0020_Assignment.title])",
  "defaultHoverField": "[$Current_x0020_Assignment]" 
}

Interestingly, the hover functionality is automatically not applied to the Not assigned text values, which is great (i.e., I don't need to apply extra conditional structures to handle that scenario).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.