Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Method to sort in picklist works in click handler bot not in form onload handler

$
0
0

Hello,

we have a picklist with aprox. 1000 entires.  We want to sort the Labels when used with other languages than the default language. We added the following function to the click handler of the picklist dropdown. Sorting works, but it needs some time to sort these 1000 entries when the user tries to open it.

So we try to sort the list when the user opens the form. So we call this code in the Form onload handler (asynchronous with setTimeout). But it does not work anymore in the onload handler. I tried it asynchronous and synchronous. It makes no difference.

It still generates the sorted list optionsSorted, but it seems to ignore the calls to picklist.clearOptions and pickList.addOptions.

What might be the reason for that. Does these methods not working in the Forms onload handler. Do I miss something else?

Regards

Rolf

 this.SortPicklist = function (picklistToSort) {
        var picklist = Xrm.Page.getControl(picklistToSort);
        var picklistAttribute = picklist.getAttribute();
        var optionsSorted = picklistAttribute.getOptions().sort(this.OnValuesCompared);

        picklist.clearOptions();

        for (var i = 0; i < optionsSorted.length; i++) {
            if (optionsSorted[i].value != "null") {
                picklist.addOption(optionsSorted[i]);
            }
        }
    };

this.OnValuesCompared = function (a, b) { if (a.text.toLowerCase() < b.text.toLowerCase()) return -1; if (a.text.toLowerCase() > b.text.toLowerCase()) return 1; return 0; };



Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>