2

In my portal (Sharepoint Server 2010 Enterprise) I have a simple list with only the title field. I've created about 50 entries in the list.

In another list, I have a lookup column that pulls from the first list, and I want to be able to edit this list in GANTT view.

There is a similar post here, but the accepted solution was to not allow multiple choices in the destination column. The user is allowed to select multiple values from the dropdown list.

My issue is that items in that dropdown seem to be arranged in the order that they were created in the original list. It makes it very hard to find what you want to select!

How can I force that dropdown list into alphabetical order?

[edit]

Ah, I've discovered the issue only happens in GANTT view. It works fine in datasheet view.

[update]

Now, I found this page, with some ideas, and workarounds but not solutions. Maybe it would give someone some insight? The fellow had the same problem and was fighting hard.

This fellow suggests using jQuery, but doesn't provide a Sharepoint-adapted solution. Here is another jQuery solution, but I can't get it to work in a GANTT view.

Is there a way to force it to alphabetical order by editing the view's aspx page in Sharepoint Designer, perhaps?

5 Answers 5

3

I don't know if this could be considered an answer as opposed to just a comment. I don't have enough reputation to post a comment, but I can post an 'answer'. :D

You can't use SP Designer to customise a Gantt View in SP2010, unfortunately.

As for javascripting, I did a bit of digging on this by creating a Gantt view with a lookup, and then I copied the markup that SP generates when it creates the lookup field dropdown menu. For the dropdown menu, SP generates a table with 3 columns: one for the checkbox, one empty, and another for the display text. I managed to sort the table markup for the dropdown menu (see here).

However, the way the Gantt View dropdown appears to determine the item you select is based on the order of the items in the menu. So sorting it messes up how the dropdown works. Please note this is based on my observation of the control looking at it through FireFox's Inspect tool, as I did not check SP's (many) javascripts for (or that appear to relate to) a Gantt view.

Also, the dropdown is added after the Gantt view is loaded--it appears to be inserted when you click on the cell, and after you click on the dropdown button. IMHO, it is not worth sorting it via javascript.

Anyway, if you want to know the script I added (in a CEWP) to sort, here it is. But as I said, it messes up the dropdown item selection. I had to bind to the grid id (which may be different for your view). I have not tested this on lists with multiple lookups.

<script type="text/javascript">
if (window.addEventListener) {
    window.addEventListener('load', bindsort, false); 
} 
else if (window.attachEvent) { 
    window.attachEvent('onload', bindsort); 
}

function bindsort() {
    jQuery('#ctl00_m_g_ccd336a1_7da5_4212_a646_6a499e53404f_ListViewWebPartJSGrid').on(
        'click', '#jsgrid_combobox',
        function () { sortlkupddm(); });
}

// Sort the dropdown menu for the lookup field.
function sortlkupddm(){
    setTimeout( function () {
        var rows = jQuery('#jsgrid_combobox table.combobox-panel-table>tbody>tr.cb-dp-rw').detach();

        // Sort assuming text content.
        rows.sort(function (row1, row2) {
            var v1 = jQuery(row1).find('span.jsgrid-control-text').text();
            var v2 = jQuery(row2).find('span.jsgrid-control-text').text();
            if (v1 < v2) return -1;
            else return 1;
        });
        jQuery(rows).each(function(){
            jQuery('table.combobox-panel-table>tbody:last').append(jQuery(this));
        });
    }, 200);
}
</script>
2
  • Ah, this is indeed, an answer - kind of like what I was hoping for. I'll try this out either tonight or tomorrow morning and give you my appraisal. Thanks!
    – bgmCoder
    Commented Aug 4, 2013 at 16:22
  • Frank, thank you for your time on this question. Your research was very thourough.
    – bgmCoder
    Commented Sep 9, 2014 at 14:53
1

If you don't already have anything that is linked to that list as a lookup, you can do that manual switch. HOWEVER, be aware, that anything you already had linked into that list will change if you delete your data and reimport with the sorted values.

You risk doing more harm than good that way.

You're better off finding a solution that will allow for growth of the lookup list.

1
  • Thanks for the response, Sally, but maybe you have an idea what that solution might be?
    – bgmCoder
    Commented Sep 11, 2014 at 22:53
0

I was able to successfully do this manually. The easiest way is to switch to data sheet view, copy the content to Excel. Then sort your list. Delete the rows in the original list and paste the sorted content back from Excel. As your new list items are added on paste, the Item ID is assigned in the order pasted. Viola! Your lookup dropdown is alphabetical.

SP2010 & Office2010

Edit: Repercussions!!-The lookup column that used this list lost all the data. I had to go back and restore the list items. So, be careful with lookup columns.

0

You can only make this whith a list definition, unfortunately you can not make it with the UI. You have to Add your orderby in the View having BaseViewId 0. That worked for me

-1

In your source list, try changing the default view to sort by Title instead of by ID and see if this affects your lookup column.

1
  • 1
    In the source list, it's already sorted alphabetically, at least in the "All Items" view it is - but that's the only view. No, it doesn't make any difference.
    – bgmCoder
    Commented Aug 2, 2013 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.