Sorting $list by a "sub" $list

I have the following code to show a list of cell phones, which it grabs from the mobilePhone tag. Since not all mobilePhones have assigned users, it then goes through the user tags to find which ones have a cellPhone field equal to the current Cell phone. It puts this value in a variable so that I can put in a placeholder for the phones that have no user. Further down I get some more information about the phones from the mobilePhone and the phoneHardware tags.

What I’d like to do is sort it by the user name and I’d like to have all the ones that say spare instead of a name appear at the top of the list.

Hopefully that came across clear. Here is my code below (not sure if I am supposed to just paste it in or if there is a required format). This is my first day with TiddlyWiki, so if someone could point me towards the documentation where I could have found this answer myself, that would also be very helpful.

Thanks in advance.

<table>
<$list filter="[tag[mobilePhone]]" sort="[tag[user]]+[field:cellPhone{!!title}]">
<tr>
<$set name = "person" filter = "[tag[user]]+[field:cellPhone{!!title}]" emptyValue="Spare Phone" select=0>
<td>
<$link to=<<person>>/>
</td>
</$set>
<td><$link to=<<!!title>>/></td>
<td><$link to={{!!IMEI}}/></td>
<td><$view field= "planType"/></td>
<td><$view field= "simNo"/></td>
<$list filter="[tag[phoneHardware]]+[field:title{!!IMEI}]">
<td><$view field= "make"/></td>
<td><$view field= "model"/></td>
</$list>

One approach is to have two lists, one with empty users and one with non-empty users.

Here’s a go – without trying to replicate your tables, but achieving the basic ordering you want, if I follow correctly.

Your case is tricky because you’re listing one thing, and sorting by a value that isn’t anywhere to be found within the tiddlers being listed, or so it seems…

But a workaround involves using a funny trick based on the “dominant append” pattern that TiddlyWiki filters use.

What this list filter does: It starts by getting all the tiddlers tagged mobilePhone, and then goes on to add in all the contents of users’ cellPhone fields, sorted by user.

Numbers that appear on the second list – even if they also appear on the first list – automatically end up at the end of the whole sequence. So, only the mobilePhone titles that do not appear in any user’s cellPhone field remain at the top, followed by all the assigned numbers (sorted by the title of the user-tiddler listing them as cellPhone).

Does this achieve the basic effect you were hoping for?

<$list filter="[tag[mobilePhone]] [tag[user]sort[]each[cellPhone]get[cellPhone]]">

<$text text={{{ [<currentTiddler>listed[cellPhone]else[SPARE]] }}}/> <$link/> {{!!cellPhone}} {{!!IMEI}} 
</$list>

Thank you very much. That makes perfect sense. However I don’t know how to show alll the data from mobilePhones, except for the values that exist in user field:cellPhone.

That worked perfectly. I don’t quite understand what you did, but it worked, and now I will pick it apart until it makes sense to me.

Thank you very much.

To follow the explanation, you might want to check out the docs on Dominant Append. Enjoy!

To list items with a field containing a value use has[fieldname] to list including empty use has:field[fieldname] and to list only empty combine them has:field[fieldname]!has[fieldname] note the !