How To Filter The Rows Based on Values of Column Without Iterating Through All Rows
Hi Friends,
In this post I am going to show you how you can get all the rows based on some value of column without iterating through each rows.
Scenario: Suppose you have a table which is consisting a checkbox to select some of the rows and based on selected rows you want to process some logic for all the selected rows.
Usually what we do is, we create a RowSetIterator and then iterate through each rows and then compare the value for the checkbox whether it is checked or not. So we usually write the code something like this.
RowSetIterator rs=this.createRowSetIterator(null);
rs.reset();
while(rs.hasNext()){
Row row=rs.next();
if("S".equals(row.getAttribute("IndSel"))){
// here your logic based on selection
}
}
But you can also get all selected rows without iterating through each rows.
To do so you have to write the following code instead of above code.
RowSetIterator rs=this.createRowSetIterator(null);
rs.reset();
Row r[]=rs.getFilteredRows("IndSel", "S");
System.out.println(r.length);
for (int i = 0; i < r.length; i++) {
System.out.println(r[i].getAttribute("FirstName"));
}
This will be faster from above code as we are iterating through those rows only which are checked.
When you click on the button just below the table then you will get the desired result as below:
4
Lisa
kunal
Steven
Alexander
In this post I am going to show you how you can get all the rows based on some value of column without iterating through each rows.
Scenario: Suppose you have a table which is consisting a checkbox to select some of the rows and based on selected rows you want to process some logic for all the selected rows.
Usually what we do is, we create a RowSetIterator and then iterate through each rows and then compare the value for the checkbox whether it is checked or not. So we usually write the code something like this.
RowSetIterator rs=this.createRowSetIterator(null);
rs.reset();
while(rs.hasNext()){
Row row=rs.next();
if("S".equals(row.getAttribute("IndSel"))){
// here your logic based on selection
}
}
But you can also get all selected rows without iterating through each rows.
To do so you have to write the following code instead of above code.
RowSetIterator rs=this.createRowSetIterator(null);
rs.reset();
Row r[]=rs.getFilteredRows("IndSel", "S");
System.out.println(r.length);
for (int i = 0; i < r.length; i++) {
System.out.println(r[i].getAttribute("FirstName"));
}
This will be faster from above code as we are iterating through those rows only which are checked.
When you click on the button just below the table then you will get the desired result as below:
4
Lisa
kunal
Steven
Alexander
Is it possible to have multiple filters on a rowsetIterator?
ReplyDeleteHow to achieve the same in OAF ?
ReplyDelete