DataTable: draggableRows -> wrong value sent to view after reordering
See original GitHub issue1) Environment
- PrimeFaces version: 7.0.9
- Does it work on the newest released PrimeFaces version? Version? No
- Does it work on the newest sources in GitHub? (Build by source -> https://github.com/primefaces/primefaces/wiki/Building-From-Source) No
- Application server + version: WildFly 10.1.0
- Affected browsers: All
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.
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:
- Created 4 years ago
- Comments:19 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can you try your sample above using the trick they suggested the
<p:ajax event="rowReorder" update="@this"/>
to the datatable?The workaround provided is the solution desired by PrimeTek not to break other functionality.