0

Whenever I apply a filter to a list view using the default filter options, my script web part stops responding. The code I'm using for the web part is:

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
$("tr").click(function()
{

    var clickedId = this.id;
    if (clickedId != "")
    {
        var realId = clickedId.split(',');
        SP.UI.ModalDialog.showModalDialog(
        { 
            //url to open on click
            url: 'EditForm.aspx?ID=' + realId[1],
            dialogReturnValueCallback: function(dialogResult) 
            { 
                SP.UI.ModalDialog.RefreshPage(dialogResult) 
            }
        });
    }
return false;
});
});
</script>

What this code does is open an edit form dialog whenever an item is clicked, after which it refreshes the page. Can anyone explain to me why this piece of code stops responding after applying a filter through the list view interface?

  • Okay so I found out some more things. Not only does applying a filter break the script, so does going to the next 30 items in the list. – P. Schotman Mar 24 '15 at 14:06
  • Apparently you need to use the on() function rather than the click() function of jquery. The problem is though that while $("table tbody tr td table tbody tr").on("click", function() { seems to work (except on updating the table), $("table tbody tr td table tbody").on("click", "tr", function() { does nothing. – P. Schotman Mar 25 '15 at 9:20
0

I have fixed my problem by not looking for a click event but a mousedown event on the table. The code:

<script src="https://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>

$(document).on("mousedown", ".ms-itmHoverEnabled", function(e) {
    var clickedId = this.id;
    if (clickedId != "")
    {
        var realId = clickedId.split(',');
        SP.UI.ModalDialog.showModalDialog(
        { 
            //url to open on click
            url: 'EditItem.aspx?ID=' + realId[1],
            dialogReturnValueCallback: function(dialogResult) 
            { 
                SP.UI.ModalDialog.RefreshPage(dialogResult) 
            }
        });
    }   
});

</script>

Hope this might help people wanting to click on a row withtin a sharepoint 2013 list view.

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.