Ok, so this might sound trivial, and it's been asked a billion times before, and i have done it a billion times before, until now.
So at work ive done some sites that sort nodes etc. based on a user picked date. Right now i am working on a private project, where a user can pick events, the events are sorted in folders using DateFolders package according to the user chosen date.
All that works like a charm, and the events can be displayed on a list. But if an event was created with a date between the other dates, or earlier, it's appears on the end of my list obviously.
So here i thought "oh will just sort like always!" But it doesnt work. It makes no sense, ive done this before but nothing happens.
(excuse the lack of proper formatting, but the forum posting system refuses to work correctly)
"startTid" is a date picker with time property which states the start of the event. (there is also one for end of the event, but it doesnt matter here). I usually write just the name of the property followed by normalize space. But that didnt work. I then tried other methods found on the forums but still nothing.
Code looks fine - problematic areas could be the documentTypeAlias of course or the property name being misspelled, which it probably isn't ...
Most likely it's the startTid property that's not filled in (that would make it "sort" at the end of the list).
/Chriztian
PS: Using normalize-space() is done like this: select="normalize-space(propertyName)" - it's a function - you send in the element you want to normalize and get the normalized result back.
Thank you for your reply. Well the normalize-space is a habit i picked up from another programmer. Technically it should work fine without.
anyway, the property name is without doubt correct, and it can be read because DateFolder organizes correctly according to that specific property. If something isnt filled out, then it's time. Could that be the culprit? Should i perhaps sort after a formatted datetime? But it should still work as is, regardless.
Also i tried sorting by nodename, works fine. Hmm...
Not filling out the time part would make the event sort at the end too (it would be a shorter string than the rest of them), yes - guess that's your problem then.
If the time doesn't matter, then you could just use the date part in all nodes, e.g.:
Hmm, this might be more complicated then... Even if it's a datepicker with time, property, an event can either be one or several days (hence the need for an end date as well) or a single day, where time of day is needed. So some events have a date with time that says 19:30 one might have 00:00. But it should sort just by date and not time (there wont be two events on any given day anyway).
The substring you posted, what part of the date does it pick? (just tried it, doesnt work sadly)
Sorry for bumping, it would just be great for some help with this because i can find no solutions anywhere, and it's even more difficult seeing as my code is "correct". Chriztian's code does not work, but would help if i could understand the meaning of it.
So, if the startTid property is in fact a standard DateTime value, then you'd get only the date part.
You say that doesn't work, so I'd strongly suggest you post some XML here for us to see - maybe just do a <xsl:value-of select="startTid" /> inside the for-each ...?
Ok, just disregard what i just wrote here if anyone saw it. I found the error which obviously was me who should have used "ascending". The funny thing is, it was actually sorting, but compared to "created date" which it sorts by per default, it somehow sorted exactly the same way, thereby confusing me and leading me to believe it didnt work. So it did sort, but the result was just exactly the same. Oh god i feel so stupid.
Thank you for your time Chriztian, i greatly appreciate it, and of course you putting up with my constant posts forever solidifying my density.
Can not sort by date for some reason
Ok, so this might sound trivial, and it's been asked a billion times before, and i have done it a billion times before, until now.
So at work ive done some sites that sort nodes etc. based on a user picked date. Right now i am working on a private project, where a user can pick events, the events are sorted in folders using DateFolders package according to the user chosen date.
All that works like a charm, and the events can be displayed on a list. But if an event was created with a date between the other dates, or earlier, it's appears on the end of my list obviously.
So here i thought "oh will just sort like always!" But it doesnt work. It makes no sense, ive done this before but nothing happens.
(excuse the lack of proper formatting, but the forum posting system refuses to work correctly)
<ul class="disc">
<xsl:for-each select="umbraco.library:GetXmlNodeById(1064)//* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
<xsl:sort select="startTid" order="descending" />
<li>
<xsl:choose>
<xsl:when test="showEndDate = '1'">
...show some node information...
</xsl:when>
<xsl:otherwise>
...show node information...
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:for-each>
</ul>
"startTid" is a date picker with time property which states the start of the event. (there is also one for end of the event, but it doesnt matter here). I usually write just the name of the property followed by normalize space. But that didnt work. I then tried other methods found on the forums but still nothing.
Hi Frederik,
Code looks fine - problematic areas could be the documentTypeAlias of course or the property name being misspelled, which it probably isn't ...
Most likely it's the startTid property that's not filled in (that would make it "sort" at the end of the list).
/Chriztian
PS: Using normalize-space() is done like this: select="normalize-space(propertyName)" - it's a function - you send in the element you want to normalize and get the normalized result back.
Thank you for your reply. Well the normalize-space is a habit i picked up from another programmer. Technically it should work fine without.
anyway, the property name is without doubt correct, and it can be read because DateFolder organizes correctly according to that specific property. If something isnt filled out, then it's time. Could that be the culprit? Should i perhaps sort after a formatted datetime? But it should still work as is, regardless.
Also i tried sorting by nodename, works fine. Hmm...
Hi Frederik,
Not filling out the time part would make the event sort at the end too (it would be a shorter string than the rest of them), yes - guess that's your problem then.
If the time doesn't matter, then you could just use the date part in all nodes, e.g.:
/Chriztian
Hmm, this might be more complicated then... Even if it's a datepicker with time, property, an event can either be one or several days (hence the need for an end date as well) or a single day, where time of day is needed. So some events have a date with time that says 19:30 one might have 00:00. But it should sort just by date and not time (there wont be two events on any given day anyway).
The substring you posted, what part of the date does it pick? (just tried it, doesnt work sadly)
I know i am missing something obvious...
Sorry for bumping, it would just be great for some help with this because i can find no solutions anywhere, and it's even more difficult seeing as my code is "correct". Chriztian's code does not work, but would help if i could understand the meaning of it.
Hi Frederik,
The substring takes the first 10 characters of a standard date field, e.g:
So, if the startTid property is in fact a standard DateTime value, then you'd get only the date part.
You say that doesn't work, so I'd strongly suggest you post some XML here for us to see - maybe just do a <xsl:value-of select="startTid" /> inside the for-each ...?
/Chriztian
EDIT
Ok, just disregard what i just wrote here if anyone saw it. I found the error which obviously was me who should have used "ascending". The funny thing is, it was actually sorting, but compared to "created date" which it sorts by per default, it somehow sorted exactly the same way, thereby confusing me and leading me to believe it didnt work. So it did sort, but the result was just exactly the same. Oh god i feel so stupid.
Thank you for your time Chriztian, i greatly appreciate it, and of course you putting up with my constant posts forever solidifying my density.
Don't feel stupid, Frederik :-)
Now you've got some solid "muscle memory" on a particular problem, which is the best "memory management" mnemonic technique I've ever found ... :)
/Chriztian
is working on a reply...