Click here to Skip to main content
13,352,161 members (70,216 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 23 Apr 2012

SharePoint 2007 Sort Post in Discussion Board

, 23 Apr 2012
Rate this:
Please Sign up or sign in to vote.
Sort posts in Discussion Board in SharePoint 2007

In SharePoint 2010 Discussion Board, sorting the created date in descending order will yield the result shown in figure 1. It will automatically pin the first post on the top and order the rest of the posts in descending order.

Figure 1

SharePoint 2010 discussion board view

On the other hand, SharePoint 2007 will yield the result similar to figure 2. It will place the most recent post on the top and the initial post at the bottom of the list. So, how can we achieve the similar result in SharePoint 2010? I saw a post suggesting creating a new column, in the view, sort by the new column and then the created date. I think that is a brilliant idea but the problem with that approach is that the new column will appears in the form. The extra input field in the form might confuse the users when they are trying to submit/edit a new discussion or reply to a post.

Figure 2

SharePoint 2007 discussion board view

Another approach is to use jQuery to rearrange the row in the list. Shown below is the script that I use to manipulate the list. Add a Content Editor Web Part on to the page and place the script in listing 1 using the source editor. Here is a brief explanation on how the script works. The JavaScript will access the element by class name to get the number of rows in the list and then move the last two rows on top of the list. You can download the jquery-latest.js JavaScript file and upload to library or list in your SharePoint Site. Then modify the src attribute to point to the location of the JavaScript.

Listing 1

<script src=""></script>

 <script type="text/javascript">
     $(document).ready(function () {
//get the number of rows.
         var rowCount = parseInt($("table .ms-disc > tbody > tr").length);
         //rowCount - 2 -- body  //rowCount - 3 -- header
         var $lastRowHeader = $("table .ms-disc > tbody > tr:eq(" + (rowCount - 3) + ")");
         var $lastRowBody = $("table .ms-disc > tbody > tr:eq(" + (rowCount - 2) + ")");
         $("table .ms-disc > tbody > tr:eq(" + (rowCount - 2) + ")").remove();
         $("table .ms-disc > tbody > tr:eq(" + (rowCount - 3) + ")").remove();
         $("table .ms-disc > tbody > tr:eq(1)").before("<tr>" + $lastRowHeader.html() + "</tr>");
         $("table .ms-disc > tbody > tr:eq(2)").before("<tr>" + $lastRowBody.html() + "</tr>");

Here how the view will look like using the JavaScript. Please keep in mind that this script only works with flat view.

Figure 3

SharePoint 2007 discussion board view using script


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bryian Tan
Software Developer (Senior)
United States United States
I have over 10 years of experience working with Microsoft technologies. I have earned my Microsoft Certified Technology Specialist (MCTS) certification. I'm a highly motivated self-starter with an aptitude for learning new skills quickly.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 24 Apr 2012
Article Copyright 2012 by Bryian Tan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid