FeatureTable widget some rows set highlight the background color?

89
1
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
1 Reply
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