How to do conditional formatting on the SharePoint List field values using SPFx - Field Customizer?
How to do conditional formatting on the SharePoint List field values using SPFx - Field Customizer?
658 views Asked by Deepika Edakkoth At
1
There are 1 answers
Related Questions in TYPESCRIPT
- Best way to make an HABTM association via console
- undefined method `namespace' for main:Object (NoMethodError) - active record / rakefile
- Ruby destroy is not working? Or objects still present?
- Trying to set the value of an input with mechanize
- How to split the logic in a ruby game
- How can I monitor an endpoint's status with Ruby?
- Why can a private class method be explicitly invoked in Ruby?
- Rails - Ajax do not work properly on production server
- syntax error, unexpected kEND
- Carrierwave file upload with different file types
Related Questions in SHAREPOINT
- Best way to make an HABTM association via console
- undefined method `namespace' for main:Object (NoMethodError) - active record / rakefile
- Ruby destroy is not working? Or objects still present?
- Trying to set the value of an input with mechanize
- How to split the logic in a ruby game
- How can I monitor an endpoint's status with Ruby?
- Why can a private class method be explicitly invoked in Ruby?
- Rails - Ajax do not work properly on production server
- syntax error, unexpected kEND
- Carrierwave file upload with different file types
Related Questions in SHAREPOINT-ONLINE
- Best way to make an HABTM association via console
- undefined method `namespace' for main:Object (NoMethodError) - active record / rakefile
- Ruby destroy is not working? Or objects still present?
- Trying to set the value of an input with mechanize
- How to split the logic in a ruby game
- How can I monitor an endpoint's status with Ruby?
- Why can a private class method be explicitly invoked in Ruby?
- Rails - Ajax do not work properly on production server
- syntax error, unexpected kEND
- Carrierwave file upload with different file types
Related Questions in SHAREPOINTFRAMEWORK
- Best way to make an HABTM association via console
- undefined method `namespace' for main:Object (NoMethodError) - active record / rakefile
- Ruby destroy is not working? Or objects still present?
- Trying to set the value of an input with mechanize
- How to split the logic in a ruby game
- How can I monitor an endpoint's status with Ruby?
- Why can a private class method be explicitly invoked in Ruby?
- Rails - Ajax do not work properly on production server
- syntax error, unexpected kEND
- Carrierwave file upload with different file types
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
SharePoint Framework Field Customizer extensions enable you to customize the format of the field data in SharePoint lists. The Field Customizer is more powerful because you can use it to write any code that you want to control how a field is displayed. Here I give you a quick and simple example to render a Status field value based on conditional formatting on field values SLA Met? and Overdue Hours using SPFx Field Customizer. enter image description here
Let’s assume we have a list with four fields Title, Status, SLA Met? and Overdue Hours. The title is the default column. Status Column is a choice field and has the following values Open, InProgress, Pending, Rejected, Completed, and Closed. SLA Met? column is a Yes/No field and Overdue Hours is a Number field. My requirement was we want to display the Status column value in view form as Status value + Overdue Hours whose SLA Met? is Yes and if Overdue Hours is more than or equal to 48 Hrs then display it like days. Also, display the Status cell with colors based on each Status value.
Solution:
Open the Node.js Command Prompt
Step-1: Create a new project directory in your favorite location. md field-extension
Step-2: Go to the project directory. cd field-extension
Step-3: Create a new DataSupplier extension by running the Yeoman SharePoint Generator. yo @microsoft/sharepoint When prompted, enter the following values (select the default option for all prompts omitted below):
Step-4: What is your solution name? field-extension
Step-5: Will the components in the solution require permissions to access web APIs that are unique and not shared with other components in the tenant? (y/n) n
Step-6: Which type of client-side component to create? Extension
Step-7: Which type of client-side extension to create? Field Customizer
Step-8: What is your Field Customizer name? DataSupplier
Step-9: What is your Field Customizer description? DataSupplier description
Step-10: Which framework would you like to use? No JavaScript Framework
At this point, Yeoman installs the required dependencies and scaffolds the solution files along with the DataSupplier extension. This might take a few minutes.
Step-11: Type the following into the console to start Visual Studio Code. Code.
Step 12: Within Visual Studio Code, open the ./config/serve.json file.
Set the InternalFieldName attribute to Status for the field name, which we created. Update the pageUrl attributes to match a URL of the list. After the changes, your serve.json should look like the following code:
enter image description here
Step-13: Open the .../src\extensions\dataSupplier\DataSupplierFieldCustomizer.ts file.
Here we are using ListItemAccessor class for accessing the list items of the rendered status column. So, we should import the class from the sp-listview-extensibility package.
import { BaseFieldCustomizer, IFieldCustomizerCellEventParameters, ListItemAccessor } from '@microsoft/sp-listview-extensibility';
The following are the content of OnRendercell() methods in the solution. Also we are calling a new function from OnRenderCell() method named _getSLAValue() to check the Overdue Hours.
@override public onRenderCell(event: IFieldCustomizerCellEventParameters): void { // Use this method to perform your custom cell rendering.
Step-14: Build your code in Node.js command prompt gulp build
Step 15: Compile your code by running this command: gulp serve
This will start your default browser and load the page defined in serve.json file.
Step-16: Accept the loading of debugging manifests by selecting Load to debug scripts when prompted.
enter image description here
Now we can see the changes in the list view as shown below.
enter image description here