Hi,
How can I get index of current selected element?
Hi,
the current selected index of the component on the center stage is only available on the client (javascript) side (to improve performance).
If you want to control the carousel from server side (to know which component is currently on center stage), you can use a server side button like
this.directNavi.addValueChangeListener(change -> {
int value = this.directNavi.getValue() - 1;
Component targetComponent = carousel.getChildren().collect(Collectors.toList()).get(value);
carousel.show(targetComponent);
});
or post a feature request (or leave a reply here) and I will add this feature to the carousel component.
Hi,
I’m using your plugin with Spring Boot application (Vaadin 14.6.5) to make a image voting site - I need to know from the server side, which component is currently on center stage. Here is my code snippet:
@Route
public class MainView extends VerticalLayout {
public MainView() {
Carousel carousel = Carousel.create();
carousel.addComponentAtIndex(0,new Image("https://picsum.photos/600/375","img1"));
add(carousel);
}
}
Your code (“this.directNavi.”) it doesn’t make sense to me sorry - I think that I’m in different context :(
feature request:
- Can you add ie.:
a) .currentIndex() method that should return current index (index of component that is currently on center stage);
b) .currentComponent() method that should return Component that is currently on center stage?
- Methods .prev() and .next() should return index number of the target item (the previous one or the next one).
I will be very grateful for considering my request :D
try it with 0.6.0
It works like a charm :D
I am impressed that I received the changes so quickly,
thanks a lot!
How to rotate the carousel to specific index?
.show(index) method do nothing :(
Button first = new Button("First element");
first.addClickListener(e-> carousel.show(0));
that is a bug with showing a component with index 0 (all other indexes should work just like in the demo application). Workaround whould be show(component) or just use 0.7.0.
Hi, I switched to 0.7.0 - nothing has changed, carousel.show(0) still do nothing, carousel.show(1) works.
Another two bugs:
- show() is not setting index value
carousel.show(1);
carousel.getSelectedIndex(); //this returns 0 not 1 !!!
- carousel.show(int) sometimes stops working after using prev() or next()
I cannot reproduce why index 0 does not work as the demo app still works. However I fixed the bug that show() did not set the component index correctly.