ListView.Sort

Discuss GUI programming with the MUI Royale plugin here
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: ListView.Sort

Post 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
djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: ListView.Sort

Post by djrikki »

Oh excellent, thanks for the swift reply.

Edit: Although column index isn't being retuned at the moment, debug line shows empty.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: ListView.Sort

Post by airsoftsoftwair »

Oh well, it should be msg.SortColumn, see here:

http://www.hollywood-mal.com/docs/html/ ... tFunc.html
djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: ListView.Sort

Post by djrikki »

Haha, okay. Both missed the typo.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

Re: ListView.Sort

Post 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)?
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: ListView.Sort

Post 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
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

Re: ListView.Sort

Post 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?
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: ListView.Sort

Post 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.
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

Re: ListView.Sort

Post 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?
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: ListView.Sort

Post 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
Post Reply