Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us at the Cloud Data and Analytics Tour! REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to sort (descending) straight table with macro

Hi,

I need to have "default sort" for straight table. I can't use simple sort, because user must be able to sort the table if he wants. So I need functionality to automatically change sort of first column when user opens table.

I was looking at API, but only found SortBy. Is there any function where you can specify what kind of sort you need - I need DESCENDING sort.

Thanks,

Miha

4 Replies
Not applicable
Author

So far - I've come to a solution:

Sub Sort_CH27
set tablebox = ActiveDocument.GetSheetObject("CH27")
tablebox.SortBy 2 ' ASC
tablebox.SortBy 2 ' DESC
End Sub

But this is not OK; If user sorts the table ASC, the next time it will be sorted ASC again, not DESC.

Thanks,
Miha

Not applicable
Author

Hey,

I used your code to get to my solution for the same problem. Here is my workin solution:

sub Sort
set a = ActiveDocument.Variables("varLastSortMenge")
var1 = a.GetContent.String

set quelle1 = ActiveDocument.GetSheetObject("CH45")
sort1 = quelle1.GetProperties.TableProperties.InterFieldSortOrder
ord1 = CStr(sort1(lbound(sort1)))

set ziel1 = ActiveDocument.GetSheetObject("CH60")
if var1 = ord1 then
ziel1.SortBy ord1
end if
ziel1.SortBy ord1

ActiveDocument.Variables("varLastSortMenge").SetContent ord1, true
end sub

Hope I could help. Variable in document musst be set before... but this is self-explanatory...

Not applicable
Author

In a straight table you can sort any column(it is by default).

So rather than definging a macro go to chart properties -->sort -->select 1st dimension (for which you wanna apply default sorting) Keep it at the top -->select descending(if numeric field) or Z-A(if text field).

then save your document.

Next time when you will open the document you will have desired sorted table.

Not applicable
Author

🙂

Think we knew this before.

I have an object to show in QV with font-size 9 and the same object to use as printreport font-size 6 to fit on page. Users should not see the reportobjects. So I have to read sort from QV-shown-object and send it to my report-object.

You have better solution for this without macro...? I need one.

Greetings,
Jonas