SharePoint lists are great for documents or simple data. Often data contains a special date, timeline, a date for which it is valid or which is important for the data entry. In the listview it might be cool to have a nice view of those entries which belong to a month or year or both. It would be cool to group items by year and month for example.
One of the requirements for a customer project was exactly this. An external list displays items which should be grouped by month.So i created a column in the bdc model for the month which has a value year month (yyyy MM, e.g. 2013 07). It also works if you are using a calculated column, but i had to do it this way cause i am working with an external list. In this case the listview is looking like this:
But instead of month numbers there should be displayed the month name. If i save the month name into the field the ordering goes wrong cause it orders alphabetically (december and then july) but i want the right order in the month. So i decided to save month number and change the listview rendering. In the end it looks as desired:
In the xsl of the listview i changed the display behavior.
At first i created a new xsl template (works like a function) and called it “get-month-name”. It has two parameters the month and the year, cause the output will be put together with “year monthname”.
[sourcecode language=”csharp”]
[/sourcecode]
In the template where your column for the month will be rendered, you add two variables. You split from the value of the column the values for the year and the values for the month and save it into different variables. That will be used to call your new template which we created earlier.
[sourcecode language=”csharp”]
[/sourcecode]
Now it’s time to call the template where the values should be displayed and transfer the variables as parameters to it.
[sourcecode language=”csharp”]
[/sourcecode]
Keep in mind that we didn’t change the values which are saved – we just changed the display properties or the rendering of the values.
In this post you can see how to expand the normal xslt stylesheet with your custom xslt stylesheet (post). I think i should also post how to make it for external lists. Hope i got some time for it soon.
..:: I LIKE SHAREPOINT ::..
Leave a Reply