0

I've one requirement in which I need to disable sorting and filtering functionalities on each column in the Quick edit mode of the list view.

I'm using SharePoint Online. I've tried below workarounds but it didn't work for me.

  • Using JavaScript and CSS in content editor webpart
  • Add the tags like Filterable="FALSE" and Sortable="FALSE" in the list view using SP Designer. It works in normal view but in quick mode it remains unchanged.

Please suggest some solution or workaround. Any help would be appreciated!

2 Answers 2

2

You can apply this css property on all the th element of the list

Suppose you want to disable Title's column filtering and sorting. Then you the below code.

SP.SOD.executeFunc('inplview.js', 'InitGridFromView', function () { });
SP.SOD.executeOrDelayUntilScriptLoaded(function () {


        if (window.InitGridFromView) {
            var baseInitGridFromView = window.InitGridFromView;
            window.InitGridFromView = function (a, c) {
                baseInitGridFromView(a, c);
                console.log('hello from grid init');
    $('th[title="Title"]').css("pointer-events","none");
            };
        }
    }, 'inplview.js');

This will disable the click functionality and therefore will disable sorting and filtering functionality.

5
  • Let me try it.. Jul 21, 2016 at 6:50
  • It's working for FF and chrome. But it's not working for IE ;( Jul 21, 2016 at 7:53
  • Its working in Edge
    – user51831
    Jul 21, 2016 at 8:58
  • Yes. I've tested. But mainly I want it for from IE9 to upper version. Jul 21, 2016 at 9:00
  • If pointer event css is not working than you should use other code which will disable click on particular th
    – user51831
    Jul 21, 2016 at 9:18
0

After lot's of googling and efforts I found the below solution.

I've added JavaScript in Content editor webpart. I've tested it in IE, Chrome and Firefox browsers. My script is as below:

<script type='text/javascript' language='javascript'>

var jsGridContainer = null;  
var jsGrid = null;
var viewId = '{9002394D-CBB9-4DDF-98DC-13DAC7C05449}';  //Pass your view id here

SP.SOD.executeFunc('inplview.js', 'InitGridFromView', function () { });
SP.SOD.executeOrDelayUntilScriptLoaded(function () {

    if (window.InitGridFromView) {
        var baseInitGridFromView = window.InitGridFromView;
        window.InitGridFromView = function (a, c) {

            SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates.TemplateManager.RegisterTemplateOverrides', function() {
                var done = false;
                SPClientTemplates.TemplateManager.RegisterTemplateOverrides({

                    OnPostRender: function(ctx) {
                        if (ctx.view != viewId || done)
                            return;

                        // Fetch JSGrid object
                        jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[viewId].jsInitObj.qualifier);
                        jsGrid = jsGridContainer.jsgrid;

                        // Make columns non-sortable and non-filterable
                        var columns = jsGrid.GetColumns();
                        for (var i in columns)
                        {
                            columns[i].isSortable = false;
                            columns[i].isAutoFilterable = false;
                        }
                        jsGrid.UpdateColumns(new SP.JsGrid.ColumnInfoCollection(columns));

                        done = true;
                    }

                });

            }); 

            baseInitGridFromView(a, c);               
        };
    }

}, 'inplview.js');

_spBodyOnLoadFunctions.push(function()
{   
    SP.SOD.executeFunc('inplview', 'InitGridFromView', function() {

        g_SPGridInitInfo[viewId].jsInitObj.canUserAddColumn = false;
        g_SPGridInitInfo[viewId].jsInitObj.showAddColumn = false;
    });

    SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates.TemplateManager.RegisterTemplateOverrides', function() {

        var done = false;
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides({

            OnPostRender: function(ctx) {
                if (ctx.view != viewId || done)
                    return;

                // Fetch JSGrid object
                jsGridContainer = $get("spgridcontainer_" + g_SPGridInitInfo[viewId].jsInitObj.qualifier);
                jsGrid = jsGridContainer.jsgrid;

                // Make columns non-sortable and non-filterable
                var columns = jsGrid.GetColumns();
                for (var i in columns)
                {
                    columns[i].isSortable = false;
                    columns[i].isAutoFilterable = false;
                }
                jsGrid.UpdateColumns(new SP.JsGrid.ColumnInfoCollection(columns));

                done = true;
            }

        });

    });

});

</script>

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.