locked
_spBodyOnLoadFunctionNames.push doesn't work with Library filters RRS feed

  • Question

  • Hi,

    I need to prepend certain values in the Document Library TD element in SharePoint Online that was inserted as a web part on a page.

    I started with jQuery and the following script (inserted via Script Editor part on the page) works on page load, BUT it breaks if I use the header filters (like sorting or selecting filter options for the columns with multiple choice settings) in the library table, on that same page -

    <script type="text/javascript">

    $(document).ready(function(){
    var $findingTableCell = $("td.ms-cellstyle");
    $("td.ms-cellstyle:nth-child(5)").prepend("Department: ");
    $("td.ms-cellstyle:nth-child(6)").prepend("Category: ");
    });

    </script>

    It only works once the page loads but when I use the filters to sort the library, it doesn't.

    I tried using SpBodyOnload as suggested at http://www.stephanrocks.com/2011/10/05/_spbodyonloadfunctionnames-in-sharepoint-vs-jquerys-document-ready/

    <script type="text/javascript">

    _spBodyOnLoadFunctionNames.push("FormCenter");
    function FormCenter() {
    var $findingTableCell = $("td.ms-cellstyle");
    $("td.ms-cellstyle:nth-child(5)").prepend("Department: ");
    $("td.ms-cellstyle:nth-child(6)").prepend("Category: ");
    }
    </script>

    BUT it still doesn't work. I am not sure if I am doing this right. Can someone please point me to how to correct this?
    The goal is to simply append a line of text to the N-th column in the library view on the page, but with the above examples, its does not work once the filters are applied.

    Greatly appreciate any help!


    Jeff V.

    Friday, September 7, 2018 9:32 PM