Header of the datatable can be fixed to keep it in viewport during scroll.
Documentation| Id | Year | Brand | Color |
|---|---|---|---|
| d67186e7 | 1969 | Volkswagen | White |
| f75dcfa0 | 1971 | Renault | Black |
| 66eb5cd6 | 1967 | Honda | Brown |
| cf6dd7a7 | 1968 | Mercedes | White |
| f74e1ca7 | 1967 | Mercedes | Blue |
| 95a6bfdd | 1996 | Volkswagen | Black |
| 655c2500 | 2009 | Volvo | Maroon |
| dc76dd66 | 2006 | Audi | Green |
| cf525d48 | 1977 | Renault | White |
| f7607a5f | 1962 | Mercedes | Red |
| cbdee600 | 1978 | Fiat | Silver |
| 70332713 | 1983 | Ford | Red |
| 0344a1bf | 1973 | Renault | Red |
| 7b9a57b3 | 2006 | Volvo | Red |
| 5f8e1dca | 1966 | Honda | Black |
| f0044ec1 | 1973 | Audi | Blue |
| 5bfe62e8 | 1993 | Audi | Red |
| 1ed01516 | 1975 | Honda | Yellow |
| 47b98ee2 | 1976 | Volvo | Orange |
| dc19b206 | 1967 | Fiat | Blue |
| 85fd15f9 | 2003 | Ford | Yellow |
| 4d0fe0a8 | 1990 | Volkswagen | Red |
| feedbc74 | 1973 | Honda | Red |
| e0391dc8 | 1978 | BMW | Yellow |
| 8b7fbf19 | 1972 | Volkswagen | White |
| 0e8bb670 | 1969 | Volkswagen | Blue |
| 64cf3611 | 1999 | Mercedes | Blue |
| 17f8bb27 | 1969 | Mercedes | Blue |
| 548ab97d | 1988 | Audi | Silver |
| 7a626c07 | 1976 | Fiat | White |
| f4372173 | 1991 | Ford | Orange |
| 05676ae1 | 1971 | Audi | Brown |
| 43658790 | 1977 | Volvo | Brown |
| 43a1e0c6 | 1986 | Audi | Yellow |
| 839dda7e | 2004 | Ford | Yellow |
| e86bf536 | 1991 | Mercedes | Maroon |
| 1489e779 | 1985 | Fiat | Maroon |
| 371f148d | 1996 | BMW | Green |
| e142427d | 1974 | Jaguar | Maroon |
| 3720a035 | 1995 | Mercedes | Silver |
| 46a5d03b | 1985 | Jaguar | Yellow |
| c66b8539 | 1961 | Honda | Orange |
| 5ceb2fec | 1993 | Volvo | Yellow |
| fa9726bb | 1993 | BMW | Black |
| 492773d2 | 1991 | Jaguar | Red |
| e8946d56 | 1977 | Jaguar | Silver |
| ec58ab87 | 1971 | Audi | Green |
| 8b028fe6 | 1984 | BMW | Orange |
| 5961cc14 | 1996 | Volkswagen | Orange |
| a634479e | 1988 | Volkswagen | Silver |
<p:dataTable var="car" value="#{dtStickyView.cars}" stickyHeader="true" stickyTopAt=".layout-topbar">
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>@Named("dtStickyView")
@RequestScoped
public class StickyView implements Serializable {
private List<Car> cars;
@Inject
private CarService service;
@PostConstruct
public void init() {
cars = service.createCars(50);
}
public List<Car> getCars() {
return cars;
}
public void setService(CarService service) {
this.service = service;
}
}@Named
@ApplicationScoped
public class CarService {
private final static String[] colors;
private final static String[] brands;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
brands = new String[10];
brands[0] = "BMW";
brands[1] = "Mercedes";
brands[2] = "Volvo";
brands[3] = "Audi";
brands[4] = "Renault";
brands[5] = "Fiat";
brands[6] = "Volkswagen";
brands[7] = "Honda";
brands[8] = "Jaguar";
brands[9] = "Ford";
}
public List<Car> createCars(int size) {
List<Car> list = new ArrayList<Car>();
for(int i = 0 ; i < size ; i++) {
list.add(new Car(getRandomId(), getRandomBrand(), getRandomYear(), getRandomColor(), getRandomPrice(), getRandomSoldState()));
}
return list;
}
private String getRandomId() {
return UUID.randomUUID().toString().substring(0, 8);
}
private int getRandomYear() {
return (int) (Math.random() * 50 + 1960);
}
private String getRandomColor() {
return colors[(int) (Math.random() * 10)];
}
private String getRandomBrand() {
return brands[(int) (Math.random() * 10)];
}
private int getRandomPrice() {
return (int) (Math.random() * 100000);
}
private boolean getRandomSoldState() {
return (Math.random() > 0.5) ? true: false;
}
public List<String> getColors() {
return Arrays.asList(colors);
}
public List<String> getBrands() {
return Arrays.asList(brands);
}
}