Saturday, May 20, 2017

Trigger SharePoint apply filter web part Action by Enter Key

    Trigger SharePoint apply filter web part Action by Enter Key


Apply Filters button that you can use to apply all the filters on the SharePoint page by a text filter or by a choice filter. One after the entry in the text filter, user need to press apply button to apply the changes. Usually customer demand for enter key action once after data input in the text filter.   You may need to include below Javascript/jquery code to achieve this. This can be included in the content editor or script editor web part.

In below example ctl00_ctl42_g_33a1df20_58a6_46b7_9656_ef6f32e42d5b_SPTextSlicerValueTextControl' is the Web part id of the Text filter web part and ctl00_ctl42_g_ec3e3fa8_03e7_4e09_b1f1_9951d415b638 is the ID of the filter web part, which you can fetch from the HTML source using developer tool for IE


<script src="/_layouts/15/STYLES/PNG.SharePoint.Core/js/jquery-1.9.1.min.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">
$(document).ready(function() {
$('#ctl00_ctl42_g_33a1df20_58a6_46b7_9656_ef6f32e42d5b_SPTextSlicerValueTextControl').keypress(function(event){
        var keycode = (event.keyCode ? event.keyCode : event.which);
        if(keycode == '13'){
           //Your Code that you want to execute or simply call the function RedirectUrl()
        event.preventDefault();
        ctl00_ctl42_g_ec3e3fa8_03e7_4e09_b1f1_9951d415b638_PostBack(event);
        }
    });

})

  
</script>

Screen Shot

No comments:

Post a Comment