Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

do not allow to sort some columns in Alv Grid

Former Member
0 Kudos

Dear friends,

Please help me.

I want to tell to the method set_table_for_first_display - make one of the columns not sortable. Let's say the column name is "My Icon".

What I mean with that is:

when User will highlight column "My icon" and then click on sort buttons in the toolbar - no sort will happen on this column.

I was trying to identify a field in lvc_s_sort which would say "do not sort this column". Is there any?

Or the only way to accomplish my task is to make sort buttons in the toolbar disable if column "My Icon" is clicked?

gt_sort TYPE lvc_t_sort.

CALL METHOD grid1->set_table_for_first_display

EXPORTING i_structure_name = 'IT'

is_layout = gs_layout

is_print = gs_print

CHANGING it_outtab = it

it_fieldcatalog = gt_fcat

it_sort = gt_sort

Thank you,

Tatyana.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Uwe,

I changed like you said:

CLEAR wa_fld.

wa_fld-fieldname = 'PROJECT'.

wa_fld-coltext = 'Project'.

wa_fld-hotspot = 'X'.

wa_fld-key = 'X'.

wa_fld-col_pos = 1.

*===txr start

wa_fld-fix_column = 'X'.

*===txr end

I am still able to sort by the 1st column by clicking Sort buttons on the Alv grid toolbar.

6 REPLIES 6

uwe_schieferstein
Active Contributor
0 Kudos

Hello Tatyana

Set the following flags in the fieldcatalog entry for your fixed columns:

<b> ls_fcat-key = 'X'.

ls_fcat-fix_column = 'X'.</b>

However, fixed columns are always at the left side of the ALV list. You cannot fix columns in the middle or on the right side of the ALV list.

Regards

Uwe

Former Member
0 Kudos

Uwe,

I changed like you said:

CLEAR wa_fld.

wa_fld-fieldname = 'PROJECT'.

wa_fld-coltext = 'Project'.

wa_fld-hotspot = 'X'.

wa_fld-key = 'X'.

wa_fld-col_pos = 1.

*===txr start

wa_fld-fix_column = 'X'.

*===txr end

I am still able to sort by the 1st column by clicking Sort buttons on the Alv grid toolbar.

0 Kudos

Tatyana,

You would need to remove the SORT buttons and then create Custom buttons that do the sorting. You would trigger your SORT code in the PAI of the screen containing the ALV grid.

In this PAI, you would validate that the column is "allowed" to be sorted. If yes, then SORT. If not, then prevent the SORT.

I see nothing in the field catalog to meet your needs w/o the solution cited above.

0 Kudos

Got a solution for ya, but you have to handle it thru coding. So you will need to handle an event from your ALV grid.

First thing is that you need a local class as your event handler, copy and paste this code. Here we are using the name ALV_GRID for your alv object



data: alv_grid       type ref to cl_gui_alv_grid.


***********************************************************************
*       CLASS lcl_event_receiver DEFINITION
***********************************************************************
class lcl_event_receiver definition.
  public section.
    methods handle_user_command
      for event before_user_command of cl_gui_alv_grid
      importing e_ucomm.
  private section.
endclass.

***********************************************************************
*       CLASS lCL_EVENT_RECEIVER IMPLEMENTATION
***********************************************************************
class lcl_event_receiver implementation.

  method handle_user_command.

    data: icols type lvc_t_col,
          xcols like line of icols.
* Get the currently selected column
    call method alv_grid->get_selected_columns
       importing
         et_index_columns = icols.

    read table icols into xcols index 1.

* If the selected column is not one that should be sorted
    check xcols-fieldname = 'MATNR'.    "<-- Whatever columns that you don't want to allow sorting on.

* Now check the function code, if sort ascending or descending, then give message
    check e_ucomm = cl_gui_alv_grid=>mc_fc_sort_asc
      or  e_ucomm =  cl_gui_alv_grid=>mc_fc_sort_dsc.
    message i001(00) with 'Can not sort on this column'.

* Now set the UCOMM as if the user didn't click anything.
    call method alv_grid->set_user_command( space ).

  endmethod.

endclass.

data: event_receiver type ref to lcl_event_receiver.

Also, you will need to set the event hanlder after calling the SET_TABLE_FOR_FIRST_DISPLAY.




  call method alv_grid->set_table_for_first_display
      changing
           it_outtab       = i_alv[]
           it_fieldcatalog = ifc[].

*  Set the handler for ALV grid
  create object event_receiver.
  set handler event_receiver->handle_user_command for alv_grid.

Just tested this, and works quite well.

Regards,

Rich Heilman

Former Member
0 Kudos

Rich,

Thank you!

It works BEATIFULLY!

I have 2 reports I just did - both containing Expand/Collapse column (just an pushbutton) which allow the User to see some subdata by clicking the pushbutton.

I noticed that if I sort by this column - then my expand/collapse functionality gets screwed up.

This is why I wanted to disallow sorting by this column.

And it works now.

Thank you VERY MUCH!

Tatyana.

0 Kudos

You are quite welcome, I had fun figuring it out.

Regards,

RIch Heilman