Page 2 of 3

Re: ListView.Sort

Posted: Sun Jul 06, 2014 2:51 pm
by airsoftsoftwair
This is how it works:

Code: Select all

Function ListViewSort(msg)
   
   debugprint(msg.entry1)   ; Table 1
   debugprint(msg.entry2)   ; Table 2
   debugprint(msg.column)   ; index
   
   Return(value)
EndFunction

Re: ListView.Sort

Posted: Sun Jul 06, 2014 7:55 pm
by djrikki
Oh excellent, thanks for the swift reply.

Edit: Although column index isn't being retuned at the moment, debug line shows empty.

Re: ListView.Sort

Posted: Sun Jul 06, 2014 8:30 pm
by airsoftsoftwair
Oh well, it should be msg.SortColumn, see here:

http://www.hollywood-mal.com/docs/html/ ... tFunc.html

Re: ListView.Sort

Posted: Sun Jul 06, 2014 9:17 pm
by djrikki
Haha, okay. Both missed the typo.

Re: ListView.Sort

Posted: Mon Sep 07, 2015 9:04 am
by GMKai
Hi,
I am at the point of sorting my listview and I need to implement a custom sort function too...

How does one mark the column the listview is sorted by?( Where do the arrows come from?)
Is there an easy way to reverse ordering?
How hard would it be to teach MUI handle integer different(compared to string)?

Re: ListView.Sort

Posted: Mon Sep 07, 2015 11:10 pm
by airsoftsoftwair
MUI Royale currently doesn't support the arrows but this is planned for the future.

Reverse sorting is really easy. Just write a callback which uses the "<" or ">" operator to compare strings alphabetically and then return -1, 0, or 1. See here: Listview.SortFunc

Re: ListView.Sort

Posted: Tue Sep 08, 2015 7:36 am
by GMKai
I have to rephrase:
Is there some function/memory available to get to know the state of a listview/column?
Where does one find out how the listview is sorted and in which direction the sort was done?
Do I have to implement state on my own or is there another way to know which sortfunction to call?

Re: ListView.Sort

Posted: Wed Sep 09, 2015 8:43 pm
by airsoftsoftwair
Since you have to implement sorting entirely on your own, there's no state you could query. How the entries are sorted is entirely determined by the way your sort function is implemented. The Listview doesn't even know that it is displaying sorted contents. It's all managed by your sort function.

Re: ListView.Sort

Posted: Wed Sep 23, 2015 8:01 pm
by GMKai
Still struggeling with custom sort.

I seem to miss the way to call my custom function.

Can you provide a minimalistic example for a custom sort solution with code and gui-definition?

Re: ListView.Sort

Posted: Sat Sep 26, 2015 2:43 pm
by airsoftsoftwair
Don't forget to install a listener on Listview.SortFunc.

Here is an example from my test suite. When you click the "Sort" button, the entries will be sorted in reverse alphabetical order.

XML file:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application base="testapp" id="app">
	<window notify="closerequest">
		<vgroup>
			<listview id="lv" sortfunc="p_comparefunc" notify="sortfunc">
				<column>
					<item>Eins</item>
					<item>Zwei</item>
					<item>Drei</item>
					<item>Vier</item>
					<item>Fünf</item>
					<item>Sechs</item>
					<item>Sieben</item>
					<item>Acht</item>
					<item>Neun</item>
					<item>Zehn</item>
				</column>
			</listview>
			<button notify="pressed">Sort!</button>
		</vgroup>
	</window>
</application>
hws source:

Code: Select all

@DISPLAY {Hidden = True}

Function p_CompareFunc(msg)

	If msg.entry1[0] > msg.entry2[0] Then Return(-1)
	If msg.entry1[0] = msg.entry2[0] Then Return(0)

	Return(1)

EndFunction

Function p_EventFunc(msg)

	Switch msg.action
	Case "MUIRoyale":
		Switch msg.attribute
		Case "CloseRequest":
			End
		Case "Pressed":
			mui.DoMethod("lv", "sort", 0)
		EndSwitch
	EndSwitch

EndFunction

mui.CreateGui(FileToString("sorttest.xml"))

InstallEventHandler({MUIRoyale = p_EventFunc})

Repeat
	WaitEvent
Forever