Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

How to auto-populate a Text Filter Web Part?

$
0
0

I am trying to figure out a way to populate a Text Filter Web Part when the page loads. The Text Filter is connected to a List View on the page. I have had a need to do this in the past, and I always get stuck and have to resort to workarounds. For my current example, I want to populate the Text Filter with the current user's username. I can't use the Current User Filter Web Part because it brings in the username in the format "Domain\Username" when my field I need to filter on in just a text field of the username without the domain. I am using JQuery and SPServices to get the current username, and I can pass it in just fine to the Text Filter, but nothing gets filtered until after I manually press Enter in the field. I tried different ways of simulating a key down press of the Enter key but nothing seems to work. Here is what I got:

<script language="javascript" src="/myPath/JQuery/jquery-1.8.2.min.js" type="text/javascript"></script><script language="javascript" src="/myPath/JQuery/jquery.SPServices-0.5.7.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">

$(document).ready(function (){
var userName = $().SPServices.SPGetCurrentUser({
                    fieldName: "UserName",
                    debug: false
                    }); 

var e = jQuery.Event("keydown");
e.which = 13; //the Enter Key

//this horribly long string is the ID of the Text Filter
$('#ctl00_m_g_e242fe64_e38a_4968_a5e1_7cbb31b8cc76_SPTextSlicerValueTextControl')
.val(userName.toLowerCase()).trigger( "keypress", [13] );

});</script>


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>