Qlikview Sort Table Box with Button

Recently, a user inquired about adding a button above a specific column so they could sort the column of the Table Box.  I instructed the user to double click the column header and the table would sort accordingly.  However, the user did not want to lose full visual of the column label, and there was not room to expand the column label to accommodate the sort arrow.  This post explains how to setup a button to sort a specific column in a Table Box.

Qlikview Sort Table Box with Button – Setup

Add the following to your LOAD SCRIPT and Reload the data:

Add a Table Box object, including the fields:  Player, Team, Week, Points

In the Table Box properties window, go to “Presentation” Tab and uncheck the Sort Indicator option:

Qlikview Sort Table Box with Button

In the Table Box properties window, go to “Caption” Tab and

  • Check the “Wrap Text” option under Multiline Caption, then set Caption Height to 2 lines
  • In the Caption Alignment section, set Horizontal to “Centered” and Vertical to “Top”

Qlikview Sort Table Box with Button

Next, add four button objects and place them above the column labels in your Table Box object.

Make sure you set the Layer to “Top” for each button, going into the Layout tab in each Button object properties window

Qlikview Sort Table Box with Button

Add the text “Sort” for each button and position and align accordingly.

Your Table Box object should look something like this:

Qlikview Sort Table Box with Button

Next, add the following Module by selecting “Tools – Edit Module” from the top menu bar.  Make sure you update the following settings:

  • Set “Requested Module Security” drop-down to “System Access”
  • Set “Current Local Security” drop-down to “Allow System Access”
  • Make sure the Table Box Object ID referenced in the macro is representing the Table Box object created above

Qlikview Sort Table Box with Button

Here is the macro code:

Next, add variable “vSortCol” to your Qlikview Application by selecting “Settings – Variable Overview” from the top menu bar

Qlikview Sort Table Box with Button

Next, in each Button object, add the following Action:

  • Add Action “Set Variable” and assign the value as pictured below (Action Type = “External”, Action = “Set Variable”)
    • Important Note:  The picture below illustrates the Action for the Button above the Table Box column “Player”.  Setting the Value to zero (0) for variable “vSortCol”
      • When you setup the actions on the other three Button objects, define the “Set Variable” Value accordingly
        • Button above “Player” field:  Variable = “vSortCol” and Value = 0
        • Button above “Team” field:  Variable = “vSortCol” and Value = 1
        • Button above “Week” field:  Variable = “vSortCol” and Value = 2
        • Button above “Points” field:  Variable = “vSortCol” and Value = 3

Qlikview Sort Table Box with Button

For each Button object, add a second Action (Action Type = “External”, Action = “Run Macro”)

  • Add Action “Run Macro” to each Button object, after the Set Variable Action
    • Macro Name = “SortChart”

Qlikview Sort Table Box with Button

That should do it!

Table Box not sorted by “Player”

Qlikview Sort Table Box with Button

Click the “Sort” Button above “Player” field, and it now sorts Ascending:

Qlikview Sort Table Box with Button

Click the “Sort” Button above the “Player” field again, and it then sorts Descending:

Qlikview Sort Table Box with Button

The same functionality is also setup for the other three Button objects!

Post any comments or questions below.  Enjoy!

 

 

 

Additional Content

Check out more examples by visiting my Home Page

Here you will find topics covering  Qlikview  SQL Server  Excel VBA

 

 

Leave a Comment