-
1. Re: Selection after sorting - ExtendedDataTable - Richfaces 4
denebj Jun 2, 2011 7:05 PM (in response to denebj)Little update, the fact that I am using an ExtendedDataModel or a simple list to display the values in the data table does not make any difference.
I changed the way of sorting, before it was done on the client side with the sort() method , and now I am sorting in the bean like in the demo (http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=dataTable&sample=tableSorting&skin=ruby).
But still no luck, after I selected a row, if I sort, then the selection in the table stays at the same row index and it does not follow the selected row !!! I do not know how to force the selection to follow the sort :-/
There is no demo for Richfaces 4 that combine the selection AND the sort feature.
Any ideas ?
Here the code of the model :
public ExtendedDataModel<User> getUserDataModel() {
if (userDataModel == null) {
userDataModel = new ExtendedDataModel<User>() {
private Object rowKey;
@Override
public Object getRowKey() {
return rowKey;
}
@Override
public void setRowKey(Object arg0) {
rowKey = arg0;
}
@Override
public void walk(FacesContext arg0, DataVisitor arg1,
Range arg2, Object arg3) {
System.out.println(" ");
for (User usr : users) {
System.out.println("Position of : " + usr.getUsrEmail()
+ " => " + users.indexOf(usr));
arg1.process(arg0, users.indexOf(usr), arg3);
setRowKey(users.indexOf(usr));
}
}
@Override
public int getRowCount() {
return users.size();
}
@Override
public User getRowData() {
return users.get((Integer) rowKey);
}
@Override
public int getRowIndex() {
return 0;
}
@Override
public Object getWrappedData() {
throw new UnsupportedOperationException();
}
@Override
public boolean isRowAvailable() {
return rowKey != null;
}
@Override
public void setRowIndex(int arg0) {
throw new UnsupportedOperationException();
}
@Override
public void setWrappedData(Object arg0) {
throw new UnsupportedOperationException();
}
};
}
return userDataModel;
}
So the output correctly show me the right indexes associated to the email that match the sort of my table !!!!
When I load the page I have :
Position of : d@hotmail.com => 0
Position of : j@gmail.com => 1
Position of : b@sagemavionics.com => 2
Position of : l@bb.com => 3
I select an item - l@bb.com , then I sort, I will have
Position of : l@bb.com => 0
Position of : dj@hotmail.com => 1
Position of : j@gmail.com => 2
Position of : b@bb.com => 3
the row selected in the table will still be the row with the index 3, which will be b@bb.com instead of l@bb.com at the row 0 after the sort.
I am not sure if I am missing something here or if is a bug or a normal behavior -Which I doubt !!!!