Recently , i had one requirement and that demands multiple row selection from Custom Table (The source of the table is from Managed Bean - java class objects).
I was trying to get the selection details using , Table.getSelectedRowKeys().iterator();
after i was iterating through that to get all the rows.
Iterator iter = table.getSelectedRowKeys().iterator();
while (iter.hasNext()) {
" get details of each row
add rows to DataList object."
}
But after this depending on the Selection rows i was doing some custom logic ,
i was thinking like what ever the order i select in the table , it gives the selected rows from top to bottom.
But when i look into the Data , its not like that.
its not following any order for sake.
Then i thought , why can't i sort that result. and introduced the below logic and that solves all confusion from this RowKeySet.
Collections.sort(DataList,COMPARATOR);
Defintion of COMPARATOR is :
private static Comparator COMPARATOR = new Comparator()
{
// This is where the sorting happens.
public int compare(GroupDataBean o1, GroupDataBean o2)
{
return o1.getIndex() - o2.getIndex();
}
};
Hope this will useful.
I was trying to get the selection details using , Table.getSelectedRowKeys().iterator();
after i was iterating through that to get all the rows.
Iterator iter = table.getSelectedRowKeys().iterator();
while (iter.hasNext()) {
" get details of each row
add rows to DataList object."
}
But after this depending on the Selection rows i was doing some custom logic ,
i was thinking like what ever the order i select in the table , it gives the selected rows from top to bottom.
But when i look into the Data , its not like that.
its not following any order for sake.
Then i thought , why can't i sort that result. and introduced the below logic and that solves all confusion from this RowKeySet.
Collections.sort(DataList,COMPARATOR);
Defintion of COMPARATOR is :
private static Comparator
{
// This is where the sorting happens.
public int compare(GroupDataBean o1, GroupDataBean o2)
{
return o1.getIndex() - o2.getIndex();
}
};
Hope this will useful.
No comments:
Post a Comment