1

enter image description here

This is my demo list, and I want to apply filter to it. However, notice that the order of the filter is alphabetic, but I want it in reverse. How can I make the order of the filter in reverse order?

ie.

havefun
have fun
haha
...

I have no idea how to describe this problem.

  • select the Descending from the that drop down – Waqas Sarwar MVP Apr 1 '15 at 18:08
  • @WaqasSarwarMCSE it will make the title sorted not the filter. – Jason Hu Apr 1 '15 at 18:12
1

You can apply a filter to your list and then right above the filter there is a sort option that you can use to sort the results in reverse order.. Maybe I'm not understanding the issue correctly?

enter image description here

  • The sort is going to sort the items and the filter will reduce the number of sorted items shown.. – Rubin Taipi Apr 1 '15 at 18:18
  • i don't want to apply filter, i just want to change the default order. – Jason Hu Apr 1 '15 at 18:49
1

With some javascript added to the view (either jslink, scripteditor, contentwebpart, customaction) it is achievable.

I tested this on an on-premise 2013 environment with September 2016 CU installed.

Since the javascript solution is overriding core javascript functionality its recommended to test this every time you update SharePoint.

function FilterOMenu(c, a) {
    //Be carefull with overriding SharePoint core functions, for now this will work (September 2016 CU). Ensure you test this every time after installing a SharePoint update.
    //SharePoint default (I placed this above, cause it returns.)
    if (a == null)
        return;
    var b = a.tagName == "DIV" ? a.parentNode : a;
    //End SharePoint default

    //Custom implementation to sort the filter
    var fieldInternalName = a.getAttribute("name");

    //some sort functions
    var ascComparer = function(a,b){return a.text<b.text ? -1:a.text>b.text ? 1 : 0;};
    var descComparer = function(a,b){return a.text>b.text ? -1:a.text<b.text ? 1 : 0;};
    var ascDateComparer = function(a,b){d1 = Date.parse(a.text);d2 = Date.parse(b.text);return d1<d2 ? -1:d1>d2 ? 1 : 0;};
    var descDateComparer = function(a,b){d1 = Date.parse(a.text);d2 = Date.parse(b.text);return d1>d2 ? -1:d1<d2 ? 1 : 0;};

    var myCustomSort = {};
    //Add the field internal name and give a comparer as value to sort
    //As example the title column as your case is
    myCustomSort["LinkTitle"] = descComparer;
    myCustomSort["Title"] = descComparer;


    if(typeof c != "undefined" && c != null && typeof myCustomSort[fieldInternalName] != "undefined"){//check if you implemented a custom sort for the current internalname
        //select all items that are checkable (the options)
        var allSelectableItems = c.querySelectorAll('[checked]');
        if(allSelectableItems.length > 0){
            var elementInnerhtmls = [];
            var htmlToReplace = "";
            var htmlToAppend = "";
            for(var i = 0;i<allSelectableItems.length;i++)
            {
                elementInnerhtmls.push({text: allSelectableItems[i].getAttribute("text"),html:allSelectableItems[i].outerHTML});
                htmlToReplace += allSelectableItems[i].outerHTML; 
            }
            elementInnerhtmls = elementInnerhtmls.sort(myCustomSort[fieldInternalName]);
            for(var i = 0;i<elementInnerhtmls.length;i++)
            {
                htmlToAppend += elementInnerhtmls[i].html;
            }
            //replace the original html with the sorted html
            c.innerHTML = c.innerHTML.replace(htmlToReplace,htmlToAppend);
        }
    }
    //SharePoint default
    OMenu(c, b, null, null, -1)
    //End SharePoint default
}    
  • I'm trying to run this on October 2016 CU, but it doesn't seem to work. As I understand, then I should use value from name tag not from DisplayName tag? Should it work, that I but this code in script editor on list page and by selecting that field, it should be filtered? – Taurib Feb 3 '17 at 12:54
  • Edit: seems, that this script doesn't run if I just put it in scirpt editor – Taurib Feb 3 '17 at 13:02
  • Inside the script editor you also should use script tags in order to run the script <script type="text/javascript">{code above}</script> – Gideon Mulder Feb 6 '17 at 8:32
  • This script seems to work while on Edit page, but not when just navigating to list page itself. – Taurib Feb 6 '17 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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