on 02-06-2015 4:53 PM
Hi All,
I am displaying set of Records in WD Application using Row Repeater UI Element. I am limiting the Visible Row Count to 8 , so if the records are more than 8 it will be displayed in the Next Page.
Able to see the records from 9 in the next page by clicking Next Page Action Button in Row Repeater.
So my question is how we can trace it out the first page or Next Page, is tere any way where we can find out the page no?
You don't need to do this through UI, instead do it manually.
1. Define a New Attribute i context "PGCNT" and default it to 8
2. In your context node which is binded to row repeater, define another attribute PAGNO (This way, you don't have to do extra bit in tracking if page no. is changed)
2. Calculate this PAGNO with reference to PGCNT by dividing and rounding it
For example, your display rows are 8 and in your context you have some 16 attruibutes, this will give the number of pages as 2. If your context has say 14 elements, then still it would be 2. While if elements exceed 16, lets say 19, your page no. would be 3.
Cheers,
VS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Santosh,
Thanks for your Reply....
My problem here is, i need to find out page no which is currently displaying...
In the Row Repeater i am displaying list of materials and calculating the Price of a materials by clicking a Button.
As we know we use a standard function module which take bit of time in calculating price.
The requirement was to determine the price of only 8 materials at a time.
For Eg if there are 24 materials ,8 materials will be displayed in Page1, other 8 will be displayed in Page 2 and last 8 will be displayed in Page 3.
When i click the Price button in that if we are in Page 1 it should find out only first 8 materials prices similarly if we are in Page2 it should find prices from 9 to 16 and in the sameay for the last page.
For doing this i need to find out on which page the user currently based on that i will calculate the Price of that page materials.
How to determine the current display page no?
There are 2 ways of doing it.
1. Add an extra variable to row repeater context. This extra element would carry the page no information. In this method you define the an extra element in your row repeater context which will carry your page number or current row index updated for each record. IAt runtime it would be like
Here, RR2_OTHER contains my data in INDEX attribute and PAGNO to store page number.
Eg, in case you have defined the visible number of rows as 2, then the context would contain the following information.
INDEX PAGNO
1 1
2 1
3 2
4 2
2. Have your own control using your own page up and down buttons.
Here you deifne your own page up and down buttons. You fill the row repeater context with your own element at run time depending on actions performed by user. For this, you need to have one global table/context node containing all data and one wrapper context node containing your lead selection/visible data. Follow the steps below
Define your context in following way where RR2_MAINS contains all your data and RR2_PAGES contains your row repeater data
Define your layout
Copy paste the following code
Add following code in INIT
*&- Set RR2 Values Here
*&- Set Main Context
DATA lo_nd_rr2_mains TYPE REF TO if_wd_context_node.
DATA ls_rr2_mains TYPE wd_this->element_rr2_mains.
DATA lt_rr2_mains TYPE wd_this->elements_rr2_mains.
* navigate from <CONTEXT> to <RR2_MAINS> via lead selection
lo_nd_rr2_mains = wd_context->get_child_node( name = wd_this->wdctx_rr2_mains ).
ls_rr2_mains-index = 1.
APPEND ls_rr2_mains TO lt_rr2_mains.
ls_rr2_mains-index = 2.
APPEND ls_rr2_mains TO lt_rr2_mains.
ls_rr2_mains-index = 3.
APPEND ls_rr2_mains TO lt_rr2_mains.
ls_rr2_mains-index = 4.
APPEND ls_rr2_mains TO lt_rr2_mains.
ls_rr2_mains-index = 5.
APPEND ls_rr2_mains TO lt_rr2_mains.
lo_nd_rr2_mains->bind_table( new_items = lt_rr2_mains set_initial_elements = abap_false ).
*&- Set Page Properties
DATA lo_nd_rr2_pages TYPE REF TO if_wd_context_node.
DATA lo_el_rr2_pages TYPE REF TO if_wd_context_element.
DATA ls_rr2_pages TYPE wd_this->element_rr2_pages.
* navigate from <CONTEXT> to <RR2_PAGES> via lead selection
lo_nd_rr2_pages = wd_context->get_child_node( name = wd_this->wdctx_rr2_pages ).
* get element via lead selection
lo_el_rr2_pages = lo_nd_rr2_pages->get_element( ).
* @TODO handle not set lead selection
IF lo_el_rr2_pages IS INITIAL.
ENDIF.
*&- Set Total No of Rows
DESCRIBE TABLE lt_rr2_mains LINES ls_rr2_pages-total.
*&- Default 1st Page as 1
ls_rr2_pages-pagno = 1.
*&- Default No of Visible Rows
ls_rr2_pages-visbl = 2.
*&- Determine Total No. of Pages
ls_rr2_pages-pages = ceil( ls_rr2_pages-total / ls_rr2_pages-visbl ).
*&- Set Button Enable/Disable Properties
ls_rr2_pages-enable = space.
ls_rr2_pages-disable = 'X'.
* set all declared attributes
lo_el_rr2_pages->set_static_attributes(
static_attributes = ls_rr2_pages ).
*&- Set Display context
DATA lo_nd_counts TYPE REF TO if_wd_context_node.
DATA ls_counts TYPE wd_this->element_counts.
DATA lt_counts TYPE wd_this->elements_counts.
* navigate from <CONTEXT> to <COUNTS> via lead selection
lo_nd_counts = wd_context->path_get_node( path = `RR2_PAGES.COUNTS` ).
DO ls_rr2_pages-visbl TIMES.
READ TABLE lt_rr2_mains INTO ls_rr2_mains INDEX sy-index.
IF sy-subrc EQ 0.
ls_counts-index = ls_rr2_mains-index.
APPEND ls_counts TO lt_counts.
ENDIF.
ENDDO.
lo_nd_counts->bind_table( new_items = lt_counts set_initial_elements = abap_false ).
Add following code in ‘NEXTPAGE’ method (Similar
code for PREVPAGE method)
*&- Get Properties
DATA lo_nd_rr2_pages TYPE REF TO if_wd_context_node.
DATA lo_el_rr2_pages TYPE REF TO if_wd_context_element.
DATA ls_rr2_pages TYPE wd_this->element_rr2_pages.
* navigate from <CONTEXT> to <RR2_PAGES> via lead selection
lo_nd_rr2_pages = wd_context->get_child_node( name = wd_this->wdctx_rr2_pages ).
* get element via lead selection
lo_el_rr2_pages = lo_nd_rr2_pages->get_element( ).
* @TODO handle not set lead selection
IF lo_el_rr2_pages IS INITIAL.
ENDIF.
* get all declared attributes
lo_el_rr2_pages->get_static_attributes(
IMPORTING
static_attributes = ls_rr2_pages ).
*&- Determine Lead index
DATA lv_leadi TYPE i.
DATA lv_loopc TYPE i.
lv_leadi = ( ls_rr2_pages-pagno * ls_rr2_pages-visbl ) + 1.
lv_loopc = lv_leadi.
*&- Get Elements at Specific Index
DATA lo_nd_rr2_mains TYPE REF TO if_wd_context_node.
DATA lo_el_rr2_mains TYPE REF TO if_wd_context_element.
DATA ls_rr2_mains TYPE wd_this->element_rr2_mains.
DATA lo_nd_counts TYPE REF TO if_wd_context_node.
DATA lt_counts TYPE wd_this->elements_counts.
DATA ls_counts TYPE wd_this->element_counts.
* navigate from <CONTEXT> to <RR2_MAINS> via lead selection
lo_nd_rr2_mains = wd_context->get_child_node( name = wd_this->wdctx_rr2_mains ).
DO 2 TIMES.
* get element via lead selection
lo_el_rr2_mains = lo_nd_rr2_mains->get_element( index = lv_loopc ).
* @TODO handle not set lead selection
IF lo_el_rr2_mains IS NOT INITIAL.
* get all declared attributes
lo_el_rr2_mains->get_static_attributes(
IMPORTING
static_attributes = ls_rr2_mains ).
ls_counts-index = ls_rr2_mains-index.
APPEND ls_counts TO lt_counts.
lv_loopc = lv_loopc + 1.
ENDIF.
ENDDO.
* navigate from <CONTEXT> to <COUNTS> via lead selection
lo_nd_counts = wd_context->path_get_node( path = `RR2_PAGES.COUNTS` ).
lo_nd_counts->invalidate( ).
lo_nd_counts->bind_table( new_items = lt_counts set_initial_elements = abap_true ).
*&- Set Table Attributes
ls_rr2_pages-pagno = CEIL( lv_leadi / ls_rr2_pages-visbl ).
ls_rr2_pages-enable = 'E'.
ls_rr2_pages-sum = 0.
if ls_rr2_pages-pagno EQ ls_rr2_pages-pages.
ls_rr2_pages-enable = 'X'.
ls_rr2_pages-disable = space.
else.
ls_rr2_pages-enable = 'X'.
ls_rr2_pages-disable = 'X'.
endif.
* get all declared attributes
lo_el_rr2_pages->set_static_attributes(
EXPORTING
static_attributes = ls_rr2_pages ).
Add following code in SUM Method
*&- Read Values Here
DATA lo_nd_counts TYPE REF TO if_wd_context_node.
DATA lt_counts TYPE wd_this->elements_counts.
DATA ls_counts TYPE wd_this->element_counts.
DATA lv_sum TYPE wd_this->element_rr2_pages-sum.
* navigate from <CONTEXT> to <COUNTS> via lead selection
lo_nd_counts = wd_context->path_get_node( path = `RR2_PAGES.COUNTS` ).
* @TODO handle non existant child
* IF lo_nd_counts IS INITIAL.
* ENDIF.
lo_nd_counts->get_static_attributes_table( IMPORTING table = lt_counts ).
loop at lt_counts into ls_counts.
lv_sum = lv_sum + ls_counts-index.
endloop.
*&- Set Values Here
DATA lo_nd_rr2_pages TYPE REF TO if_wd_context_node.
DATA lo_el_rr2_pages TYPE REF TO if_wd_context_element.
DATA ls_rr2_pages TYPE wd_this->element_rr2_pages.
* navigate from <CONTEXT> to <RR2_PAGES> via lead selection
lo_nd_rr2_pages = wd_context->get_child_node( name = wd_this->wdctx_rr2_pages ).
* @TODO handle non existant child
* IF lo_nd_rr2_pages IS INITIAL.
* ENDIF.
* get element via lead selection
lo_el_rr2_pages = lo_nd_rr2_pages->get_element( ).
* @TODO handle not set lead selection
IF lo_el_rr2_pages IS INITIAL.
ENDIF.
* @TODO fill attribute
* lv_sum = 1.
* set single attribute
lo_el_rr2_pages->set_attribute(
name = `SUM`
value = lv_sum ).
Finally you would see the following output.
Cheers,
VS
Hi VR,
I suggest you to make use of first visible row to achieve your requirement.
Sample:
DATA lo_view TYPE REF TO if_wd_view.
DATA lo_rr TYPE REF TO cl_wd_row_repeater.
DATA lv_first_vis_row TYPE i.
lo_view ?= wd_this->wd_get_api( ).
lo_rr ?= lo_view->get_element( id = 'ROW_REPEATER' ).
lv_first_vis_row = lo_rr->get_first_visible_row( ).
Here, the value lv_first_vis_row gives you the page number i.e.
for page 1 ... lv_first_vis_row = 0
for page 2 ... lv_first_vis_row = 8
for page 3 .. lv_first_vis_row = 16
....
...
Hope this helps you.
Regards,
Rama
Thank You Ramakrishnappa,
My issue is resolved with very short and precise code provide by you.
I was thinking about this first visible row count parameter but not sure how can i determine dynamically.
So in Row Repeater the first visible row can be determined through which system will understand what page the user currrently looking into.
Thank you again.
Appreciated for your help.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.