Customize column styles and rows in the Tree Grid component, with some custom CSS classes

Hello everybody,

I am using Angular 7 and Syncfusion controls 17.3.27. 
What I want to do is to customize column styles and rows in the  Tree Grid component, with some custom CSS classes.

For example round borders in the tree grid row, more spacing between rows, different font, transparent background color, and red color for headers. 
I have tried to use  [customAttributes]='customAttributes', but it seems it's not working with the dynamic columns. Here is my example on stackblitz.com, I hope that you can help me (an example is on Angular 8 and Syncfusion 14.4.51) but the result is the same, nothing is happening.


Best regards,
M

7 Replies 1 reply marked as answer

PK Padmavathy Kamalanathan Syncfusion Team December 15, 2020 09:21 AM UTC

Hi M, 
 
Thanks for contacting Syncfusion Forums. 
 
Query 1: I have tried to use  [customAttributes]='customAttributes', but it seems it's not working with the dynamic columns. 
 
We are able to set custom CSS to dynamic columns using the “customAttribute” property of Tree Grid columns. In your sample, we have set “customcss” class to the “customAttribute” property of “taskID” column and it works as expected.  
 
NOTE: The style customization works only when we elevate the CSS to global scope using the encapsulation: ViewEncapsulation.None. If you need to apply style for ViewEncapsulation other than None, use ng-deep like shown in the below help documentation, 
 
Please check the below code snippet, 
 
Solution using ViewEncapsultion.None 
  
  private createTreeGridColumns() { // method for dynamic column 
    return [ 
      { 
        field: "taskID", 
        headerText: "Task ID", 
        editType: "defaultedit", 
        customAttributes: { class: "customcss" } 
      },  
    ]; 
  } 
  
Please check the below screenshot, 
 
 
  
Please check the below sample, 
 
Please check the below help documentation, 
 
Query 2: more spacing between rows 
 
You can customize the row height of treegrid rows through the rowHeight property. Please check the below help documentation, 
 
If you face any issues in implementing the above solution, kindly get back to us with the below requested details, 
  1. Complete Tree Grid rendering code with CSS customization
  2. Video demo and Screenshot of issue/requirement
  3. If possible, share us issue reproducible sample or reproduce the issue in the sample shared above.
 
Regards, 
Padmavathy Kamalanathan           


Marked as answer

MM MM December 17, 2020 01:50 PM UTC

Thank you for the quick answer.
Manage to change almost everything but round borders in the rows and higher spacing between the rows are not easy.
Something like this, maybe you can help me.






PS Pon Selva Jeganathan Syncfusion Team December 18, 2020 02:55 PM UTC

  
  
Hi MM,   
  
Thanks for the update.   
  

Query1: round borders in the rows 

 

We achieved your query by using border radius and background color property in CSS class. Please refer to below code snippet, 

 

  
Your CSS code:  
.e-treegrid .e-headercell.customcss {  
  font-family:  'sans-serif' 
  colorblue 
  text-alignstart 
  border-stylenone 
 
  
  
Modified code:  
  
.e-treegrid .e-headercell.customcss {  
  background-color#2382c3;  
  font-family"sans-serif" 
  colorred 
  text-alignstart 
  border-radius50px;  
 
   

 

 

Please refer to the below screenshot: 

 

 

 

Please refer to the below sample:  

 https://stackblitz.com/edit/angular-custom-css-vr3xsz?file=app.component.css 

 

Query2:  higher spacing between the rows  

 

Based on your query, we've modified the row height using 'rowHeight' treegrid property. Please refer to the below code example 

 

Your CSS code:  
<ejs-treegrid id='TreeGrid' ….. (rowDrop)='rowDrop($event)'  
        (rowDragStart)='rowDragStart($event)' (rowDrag)='rowDrag($event)' [columns]="treeColumns" rowHeight='60'  [gridLines]='lines' >  
  
  
Modified code:  
  
<ejs-treegrid id='TreeGrid'  (rowDrag)='rowDrag($event)' [columns]="treeColumns" rowHeight='30'  
        [gridLines]='lines'>  
   

 

Please refer to the below screenshot, 

 

 

  
  

Please refer to the below API documentation, demo link: 

https://ej2.syncfusion.com/angular/demos/#/material/treegrid/rowheight 

https://ej2.syncfusion.com/angular/documentation/api/treegrid/#rowheight 

https://ej2.syncfusion.com/angular/documentation/treegrid/row/#row-height 

 

If you face any issues in implementing the above solution, kindly get back to us with the below requested details,   
  1. Complete Tree Grid rendering code  
  2. Video demo and Screenshot of issue/requirement 
  3. If possible, share us issue reproducible sample or reproduce the issue in the sample shared above. 
Kindly get back us to further assitnce.  
   
Regards,   
Pon selva    



MM MM December 18, 2020 03:05 PM UTC

Hello,

Sorry, maybe you did not understand me. The border should be present only in the first column and in the last column not in every cell.
Something like this:




PS Pon Selva Jeganathan Syncfusion Team December 22, 2020 12:12 PM UTC

Hi MM,    
   

Query1: round borders in the rows  

  

We achieved query by using the border radius property in the CSS class.  We have to apply the border radius property to the first and last cell in the row.  You can add the gap between two rows in a table using the CSS border-spacing and border-collapse. Please refer to below code snippet,  

 

   
  
// change  the style on rows  
e-treegrid .e-rowcell.customcss {  
  border-radius10px 0 0 10px;  
 
.e-treegrid .e-rowcell.e-unboundcell { // last cell of the row  
  border-radius0 10px 10px 0 
}  
.e-treegrid .e-table {  
  border-collapseseparate;  
  border-spacing0 1em;  
  background-color#e0dbf3 
  bordernone 
 
.e-treegrid .e-rowcell {  
  bordernone 
 
  
  
  
// change the style on header row  
.e-treegrid .e-headercell.customcss {  
  border-radius10px 0 0 10px;  
 
.e-treegrid .e-headercell.e-lastcell.e-rightalign {  
  border-radius0 10px 10px 0;  
 
  

  

  

Please refer to the below screenshot:  

  

  

  

Please refer to the below sample:   

https://stackblitz.com/edit/angular-custom-css-7nuqdp?file=app.component.css 

   

Kindly get back us to further assistance.   
    
Regards,    
Pon selva     
 



MM MM December 22, 2020 02:41 PM UTC

Thank you.


PS Pon Selva Jeganathan Syncfusion Team December 24, 2020 02:30 PM UTC

Hi MM 
  
You are most welcome.   
  
Please get back to us if you need any other assistance.  
  
Regards,  
Pon selva 


Loader.
Up arrow icon