Search code examples
javadatagridkotlinvaadinvaadin8

Why does my slider editor not work in Vaadin 8 grid?


I want to create a Vaadin 8 grid in which I can edit the value in the column Amount (2) using a slider (analogous to this example).

Grid

I use the following code to create the grid.

fun createGrid(): Grid<Concept> {
    val grid = Grid<Concept>()
    val dataProvider = ListDataProvider<Concept>(ctl.getConcepts())
    grid.dataProvider = dataProvider
    grid.addColumn(Concept::getName)
            .setId("ID")
            .setCaption("ID")
    grid.addColumn(Concept::getDescription)
            .setId("desc")
            .setCaption("Description")
    grid.addColumn(Concept::getOutput)
            .setId("amountNumber")
            .setCaption("Amount")

    val conceptAmountditor = Slider()
    conceptAmountditor.setWidth(100.0f, Sizeable.Unit.PERCENTAGE)
    conceptAmountditor.min = 0.0
    conceptAmountditor.max = 100.0

    grid.addColumn(Concept::getOutput, ProgressBarRenderer())
            .setId("amountBar")
            .setCaption("Amount (2)")
            .setEditorComponent(
                    conceptAmountditor,
                    Concept::setOutput
            )
            .setEditable(true)


    grid.setSizeFull()
    return grid
}

But when I click on the individual rows, no slider appears.

What is wrong with my code? How can I make the progress bar transform into a slider when I double click a particular row?


Solution

  • This works:

        val amount2Col = grid.addColumn(Concept::getOutput, amount2ColRenderer)
                .setId("amountBar")
                .setCaption("Amount (2)")
        val binder = grid.editor.binder
        val amount2ColSlider = Slider()
        val amount2Binding: Binder.Binding<Concept, Double> = binder.bind(
                amount2ColSlider, Concept::getOutput, Concept::setOutput
        )
        amount2Col.setEditorBinding(amount2Binding)
        amount2Col.setEditable(true)
        grid.editor.setEnabled(true)
    

    For details see section "Editing Items Inside Grid" on this page.