Directory

← Back

EasyRender

A collection of ComponentRenderers to handle common scenarios in rendering Grid data.

Author

Rating

Popularity

<100
  • BooleanIconRenderer - Renders a configurable Icon in place of a boolean value.
  • DurationRenderer - Renders a Duration object according to a format string.
  • ImageRenderer - Renders an Image with url, alt text, width, and height, specified via ValueProviders
  • NumberRenderer - Extension of com.vaadin.flow.data.renderer.NumberRenderer with extra options
  • TemporalRenderer - Formats a java.time.temporal.Temporal using provided java.time.format.DateTimeFormatter
  • RouterLinkRenderer - Renders a router link based on options provided via ValueProviders

Sample code

package org.vaadin.addons.thshsh.easyrender;

import java.text.DecimalFormat;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.data.provider.ListDataProvider;
import com.vaadin.flow.router.Route;

@Route("demo")
public class AddonView extends Div {
	
	String[] names = {"Rob","Ashley","Victoria","Nate","Rosie","Axl","Caleb","Lucas","Trey","Dana","Beth"};
	Random random = new Random(System.currentTimeMillis());

    public AddonView() {

        List<Person> data = new ArrayList<>();
        for(int i=0;i<names.length;i++) {
        	data.add(new Person(names[i],
        	       Duration.ofMinutes(random.nextInt(60)+5),
        	       random.nextBoolean(),
        	       random.nextInt(10),
        	       OffsetDateTime.now().minusMinutes(random.nextInt(500)+100),
        	       "images/user"+i+".png"
        	        ));
        }
        
        Grid<Person> grid = new Grid<>();
        grid.setWidthFull();
        grid.setItems(new ListDataProvider<>(data));
        
        grid.addColumn(new RouterLinkRenderer<>(PersonView.class, Person::getName, Person::getId));
        
        grid.addColumn(new BooleanIconRenderer<>(VaadinIcon.CHECK, VaadinIcon.CLOSE, null, null, Person::getActive))
        .setWidth("100px").setFlexGrow(0);
        
        grid.addColumn(new DurationRenderer<>(Person::getWaited, "H'h 'm'm'"))
        .setWidth("150px").setFlexGrow(0);
        
        grid.addColumn(new NumberRenderer<>(Person::getItemCount, new DecimalFormat("#"), "", true))
        .setWidth("100px").setFlexGrow(0)
        ;
        
        grid.addColumn(new TemporalRenderer<>(Person::getTimestamp, DateTimeFormatter.ISO_OFFSET_DATE_TIME));
        
        //FIXME these images arent showing when running jetty
        grid.addColumn(new ImageRenderer<>(Person::getPictureUrl, null, "75px", null));
        
        add(grid);
    	
    }
    
    public static class Person {
        
    	String name;
    	Duration waited;
    	Boolean active;
    	Integer itemCount;
    	OffsetDateTime timestamp;
    	String pictureUrl;
    	
    	
		
		public Person(String name, Duration waited, Boolean active, Integer itemCount, OffsetDateTime timestamp, String pictureUrl) {
            super();
            this.name = name;
            this.waited = waited;
            this.active = active;
            this.itemCount = itemCount;
            this.timestamp = timestamp;
            this.pictureUrl = pictureUrl;
        }
        public String getName() {
			return name;
		}
		public void setName(String firstName) {
			this.name = firstName;
		}
        public Duration getWaited() {
            return waited;
        }
        public void setWaited(Duration waited) {
            this.waited = waited;
        }
        public Boolean getActive() {
            return active;
        }
        public void setActive(Boolean active) {
            this.active = active;
        }
        public Integer getItemCount() {
            return itemCount;
        }
        public void setItemCount(Integer itemCount) {
            this.itemCount = itemCount;
        }
        public OffsetDateTime getTimestamp() {
            return timestamp;
        }
        public void setTimestamp(OffsetDateTime timestamp) {
            this.timestamp = timestamp;
        }
        public String getPictureUrl() {
            return pictureUrl;
        }
        public void setPictureUrl(String pictureUrl) {
            this.pictureUrl = pictureUrl;
        }
		
		
		
    	
		
    }
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Released
2023-06-11
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 23+
Browser
Browser Independent

EasyRender - Vaadin Add-on Directory

A collection of ComponentRenderers to handle common scenarios in rendering Grid data. EasyRender - Vaadin Add-on Directory
* BooleanIconRenderer - Renders a configurable Icon in place of a boolean value. * DurationRenderer - Renders a Duration object according to a format string. * ImageRenderer - Renders an Image with url, alt text, width, and height, specified via ValueProviders * NumberRenderer - Extension of com.vaadin.flow.data.renderer.NumberRenderer with extra options * TemporalRenderer - Formats a java.time.temporal.Temporal using provided java.time.format.DateTimeFormatter * RouterLinkRenderer - Renders a router link based on options provided via ValueProviders
Online