FeatureTable widget some rows set highlight the background color?

549
3
Jump to solution
01-29-2023 09:39 PM
mqllin
by
New Contributor II

I have some ideas. Can I do something to dynamically set a custom highlighted background color for some rows in the table?

For example:all rows with an update table field value of 1 are set to green background.

0 Kudos
1 Solution

Accepted Solutions
mqllin
by
New Contributor II

I have achieved this effect!

I read about vaadin ui document, the framework that the table relies on, which provides a method to customize the table color. 

look code:

 

 

this.viewFeatureTable.when().then(table => {
        setTimeout(() => {
          let style = document.createElement('style');
          style.textContent = `
            .tb-row-add {
              background: rgba(54,173,71,0.3);
            }
            .tb-row-update {
              background: rgba(1,122,194,0.3);
            }
      `;
          const ref = document.getElementsByTagName('vaadin-grid')[0];
          ref.shadowRoot?.appendChild(style);
          (this.viewFeatureTable as any).grid._grid.cellClassNameGenerator = (column: any, model: any) => {
            let classes = '';
            if (model && model.item) {
              classes += column.path;
              const item = model.item;
              if (item.feature.attributes.update_type === 'add') {
                classes += ' tb-row-add';
              } else if (item.feature.attributes.update_type === 'update') {
                classes += ' tb-row-update';
              }
            }
            return classes;
          };
        }, 1000);
        this.tableToolsService.viewFeatureTable$.next(table);
      });

 

 

 

 

View solution in original post

0 Kudos
3 Replies
mqllin
by
New Contributor II

I have achieved this effect!

I read about vaadin ui document, the framework that the table relies on, which provides a method to customize the table color. 

look code:

 

 

this.viewFeatureTable.when().then(table => {
        setTimeout(() => {
          let style = document.createElement('style');
          style.textContent = `
            .tb-row-add {
              background: rgba(54,173,71,0.3);
            }
            .tb-row-update {
              background: rgba(1,122,194,0.3);
            }
      `;
          const ref = document.getElementsByTagName('vaadin-grid')[0];
          ref.shadowRoot?.appendChild(style);
          (this.viewFeatureTable as any).grid._grid.cellClassNameGenerator = (column: any, model: any) => {
            let classes = '';
            if (model && model.item) {
              classes += column.path;
              const item = model.item;
              if (item.feature.attributes.update_type === 'add') {
                classes += ' tb-row-add';
              } else if (item.feature.attributes.update_type === 'update') {
                classes += ' tb-row-update';
              }
            }
            return classes;
          };
        }, 1000);
        this.tableToolsService.viewFeatureTable$.next(table);
      });

 

 

 

 
0 Kudos
MrGIS
by
New Contributor

@mqllin I am trying to implement this on new FeatureTable. Where do you put the above code at? Can you share more of your code?

0 Kudos
mqllin
by
New Contributor II

In my code:

 

this.viewFeatureTable //that is FeatureTable()

// In some where 
this.viewFeatureTable = new featureTable({
      container: this.datatableRef.nativeElement,
      ...some other properties
)

 

After create  new FeatureTable(),use`.when()`and put the above code.

0 Kudos