question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataTable: draggableRows -> wrong value sent to view after reordering

See original GitHub issue

1) Environment

2) Expected behavior

After dragging and reordering rows in a DataTable the currently displayed value is sent to the view by an action.

3) Actual behavior

After dragging and reordering rows in a DataTable the value previously at this position is sent to the view by an action.

image

4) Steps to reproduce

Click on the commandButtons to confirm that “1” displays the growl message for TestValue with id 1 and so on. Reorder a row. Click on the commandButtons to confirm that the growl message displays the TestValues still in the 1,2,3 order and not in the order displayed after reordering the rows.

5) Sample XHTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html">

<h:head>
    <title>PrimeFaces Test</title>
</h:head>
<h:body>

    <h1>#{testView.testString}</h1>

    <h:form>

        <p:dataTable value="#{testView.testValues}"
                     draggableRows="true"
                     var="testValue">

            <p:column>
                <h:outputText value="#{testValue.id}: "/>
                <p:commandButton action="#{testView.testAction(testValue)}"/>
            </p:column>

        </p:dataTable>

        <p:growl life="8000">
            <p:autoUpdate/>
        </p:growl>

    </h:form>

</h:body>
</html>

6) Sample bean

package org.primefaces.test;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Named
@ViewScoped
public class TestView implements Serializable {

    private String testString;
    private List<TestValue> testValues;

    @PostConstruct
    public void init() {
        testString = "Welcome to PrimeFaces!!!";

        testValues = new ArrayList<>();
        testValues.add(new TestValue(1));
        testValues.add(new TestValue(2));
        testValues.add(new TestValue(3));
    }

    public void testAction(TestValue testValue) {
        FacesContext.getCurrentInstance().addMessage("id", new FacesMessage(testValue.toString()));
    }

    public String getTestString() {
        return testString;
    }

    public void setTestString(String testString) {
        this.testString = testString;
    }

    public List<TestValue> getTestValues() {
        return testValues;
    }

    public void setTestValues(List<TestValue> testValues) {
        this.testValues = testValues;
    }

    public class TestValue {
        private int id;

        public TestValue(int id) {
            this.id = id;
        }

        public int getId() {
            return id;
        }

        @Override
        public String toString() {
            return "TestValue{" +
                    "id=" + id +
                    '}';
        }
    }
}

Please see the attached test project, cloned from the primefaces-test.git. datatable-draggablerows-test.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, Nov 13, 2019

Can you try your sample above using the trick they suggested the <p:ajax event="rowReorder" update="@this"/> to the datatable?

0reactions
mellowarecommented, Nov 24, 2020

The workaround provided is the solution desired by PrimeTek not to break other functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with row reordering — DataTables forums
I'm trying to make reordering work but having problems. Clicking and dragging works but dragging moves the items for a second or two...
Read more >
i want keep same datatable row reorder even after page reload
You copy-pasted the 'row-reorder' function from the official Example, modify that so it save the order of each of your rows somewhere.
Read more >
Wrong values updating datatable with draggable rows
When using a datatable where the rows are text after changing rows order the values are updated correctly. Example: Code: Select all
Read more >
Drag & Drop to reorder table rows | Confluence Cloud - Jira
Drag and drop can be awkward in long tables. It might be easier to make moving rows available only after row numbers have...
Read more >
Laravel Datatables: Position Re-Ordering with Drag/Drop
Here's the result of what we'll be creating – in video format. ... DataTable({ buttons: dtButtons }) datatable.on('row-reorder', function (e, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found