Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Fix the sort order in a straight table

Hi,

I have a straight table, which has so many expressions.

I want to sort the table always with one expression value.

How can i do that using macro or any other method?

i have prev and next button implemented. Clicking that some expressions will be shown and others will be hidden.

so i want to sort the table based on a single expression always, even if it is hidden also.

If a user has changed the sort by clicking some column, then click on next button should retain the sort order back to the previous sort order.

How can we do that?

15 Replies
sushil353
Master II
Master II

hi,

have u tried this:

1.goto sort tab

2. click on each dimension and expression and sort them by expression. put your expression in definition box...

if this will not work then please post your sample app and describe your issue in detail.

HTh

Sushil

Not applicable
Author

Hi sushil,

I want to sort the table on clicking a button.

It should sort based on a single expression written in the chart always.

How to achieve that?

I used the below macro

Sub SortChart
Set ch = ActiveDocument.GetSheetObject("CH01")
ch.SortBy 8 '' this line specifies the expression to sort by

Set p = ch.GetProperties
Set dims = p.Dimensions
'' Dimensions start by 0
'' 0 = Disable sort
'' 1 = Sort ascending
'' -1 = Sort descending
i = dims.Item(0).SortCriteria.SortByNumeric
If i = 1 Then
  dims.Item(0).SortCriteria.SortByNumeric = -1
Else
  dims.Item(0).SortCriteria.SortByNumeric = 1
End If
ch.SetProperties p
End Sub

It works fine, but here i have given the sortby "8" th expression, but when i click the next button, it will hide first 10 expressions and shows the next 10 expressions. so that sort order changes for the 2nd "8" expression enabled.

But i want the sort to remain for the 1st "8th" expression in the table.

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

     Why do you want to use the macro, when same can be done by what Sushil has suggested.

     The reason for not using macro is, they may and may not work on browser and can slow down your application if not used properly.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
sushil353
Master II
Master II

Hi,

If it is mendetory to have button to sort your table. then try this.

1. create a variable: say--- vsort

2. in the sort tab for expression sort put some condition like: if(vsort=1,expression)

here expression is your expression on which you want to sort the table

3. creat a button and set the variable value 1 on click.

It is better to avoid macros..

HTH

Sushil

Not applicable
Author

The problem is,

The user can sort the columns manually by double clicking columns.

Then the sort order will change, but i want the sort order should come back to previous state by clicking the "Next" button in my application qvw file.

Not applicable
Author

Sushil,

I tried the method, it is not working in my file.

I change the sort order, by double clicking some other expression.

And i applied the sort expression for the dimension to sort in the table.

It is not sorting the dimension based on the expression value.

sushil353
Master II
Master II

Please post the sample app.

Not applicable
Author

It has the client data, so sorry i cannot post the file

Not applicable
Author

Can you tell me how we can modify the above macro, so that we can achieve this on clicking the button.