cancel
Showing results for 
Search instead for 
Did you mean: 

To determine the number of rows selected in a table view (BSP)

Former Member
0 Kudos

Hi,

My requirement is:

I would be selecting 1 row from a table view ( which is made multiselect for another requirement) , and press a button.

The functionality of button is to open a popup window based on the row selected.

I want to display an error message if more than 1 row is selected, and button is clicked.

Message will say that "you cannot select more than 1 row".

For this, I need to know how I can get the number of selected rows in a table view.

I tried using the below code.

But I feel this will work only in DO_HANDLE_DATA method.

The popup would open, even before control comes in this method.

CALL METHOD cl_hrrcf_iterator=>get_tv_index

EXPORTING

p_id = p_tableview_id

pt_form_fields = table_form_fields

IMPORTING

pt_indices = sel_row_index_tab.

Could you please provide me with a solution.

Quick replies will be highly appreciated.

Thanks,

Nisha Vengal.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Nisha,

Try with the below logic represented below.

Have a column in the table view for, whether the row selected or not (eg. Include_exclude).

Use the below piece of code.

  In IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_ROW_START,
               m_row_ref ?= p_row_data_ref.
           
           In IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START.
              DATA: CHK TYPE ZFLAG.
              case p_column_key.
              when 'INCLUDE_EXCLUDE'.
                   CHK = m_row_ref->INCLUDE_EXCLUDE.
                   p_replacement_bee = CL_HTMLB_CHECKBOX=>FACTORY(
                                                                                id            = p_cell_id
                                                                                checked   = CHK ).
           In Do Request
               Data: loc_table_event type ref to cl_htmlb_event_tableview. 
               Data: Selected type i.
               call method cl_hrrcf_iterator=>get_tv_attr
                    exporting
                             p_tv_id                  = '<Table View ID>'
                             p_component_id    = me->component_id
                             po_request            = me->request
                   importing
                             po_tv_event           = loc_table_event.
           
               Selected    =  loc_table_event->get_cell_value(
                                         row_index     = indv
                                        column_index  = 1 ).
          

After this you can, include the count and print your error message.

Reward points if helpful.

Regards,

Gokul.N

former_member184111
Active Contributor
0 Kudos

Hi Nisha,

You can try something like:

Declare in page attributes or class attributes:

count type c

in OnInpurProcessig/do_handle_data:

for event rowselection:
count = count + 1 .

if count ne 1 .

msg = 'You error message'.

endif.

Regards,

Anubhav.

Former Member
0 Kudos

Hi Vijay /Anubhav,

Thank you both for your replies.

Vijay,

I looked at that BSP page. But I was not able to find anything useful.

Could you please tell me which code I should try to understand.

Anubhav,

I am triggering a client side event(pop up) on pressing that button. So it will not be possible to write the code in do_handle_data, as it will be executed only after the popup is called.

Could you please tell me another possible solution.

Thanks,

Nisha Vengal.

former_member184111
Active Contributor
0 Kudos

Hi Nisha,

Whenever a row is selected in the TV , a server side event is trigered.

In this event you can do count = count + 1

if count is more than one fill a global variable say errmsg with your error message and in the view

do something like:

<% if errmsg is not initial . %>
<s c r i p t   t y p e = " t e x t / j a v a s c r i p t " >
a l e r t ("<%= errmsg %>");
</s cript>

so the user will get popup , if he selects more than one row...

Hope it helps...

Anubhav.

Edited by: Anubhav Jain on Sep 19, 2008 1:13 PM

Former Member
0 Kudos

Hi Anubhav,

Thanks for the quick response.

Could you please explain a little more.

For which event, I should define a function ?

Thanks,

Nisha Vengal.

former_member184111
Active Contributor
0 Kudos

Hi ,

Your TV :

<htmlb:tableView id              = "tv1l"
                               design          = "alternating"
                               visibleRowCount = "10"
                               fillUpEmptyRows = "true"
                           onRowSelection  = "MyEventRowSelection" <----This is the event you have to use
                               selectionMode   = "MULTILINEEDIT"
                              filter          = "SERVER"
                               table           = "<%= some table %>" >

in DO_REQUEST:

DATA:  tv                  TYPE REF TO cl_htmlb_tableview,
       tv_event          TYPE REF TO cl_htmlb_event_tableview ,
       event             TYPE REF TO if_htmlb_data.

event = cl_htmlb_manager=>get_event( request ).

IF event IS NOT INITIAL AND event->event_name = htmlb_events=>tableview.
  tv_event ?= event.

  CASE event->event_server_name.
    WHEN 'MyEventRowSelection'.
   
count = count + 1 .
if count ne 1 .

errmsg = 'Your message'.

endif.

ENDCASE.
ENDIF.

in View/Layout:

<% if errmsg is not initial. %>
<s cript t y p e   =   t e x t / j a v a s c r i p t >
a l e r t ("<%= errmsg %>") .
</ s c r i p t>
 <% clear errmsg. %>
<% endif. %>

errmsg is a class attribute of type string and count is also a class attribute of type c .

Regards,

Anubhav.

Reward if useful

Edited by: Anubhav Jain on Sep 19, 2008 3:08 PM

former_member188685
Active Contributor
0 Kudos

Check the example SBSPEXT_TABLE

in that check this application TableViewClient.bsp