SharePoint filter Based on Startswith - sharepoint

I want to filter my sharepoint list based on what letter / number a row starts with. I know I can do this by adding a new calculated column and filter on that but I would love to be able to filter solely using the URL or JavaScript without adding a column for only that purpose. Any advice?

You can't do this just through the URL. SharePoint accepts FilterFieldxxx and FilterValuexxx querystring parameters, but they only filter exact values.
You could do it programmatically using xslt in a list view. You could also use JavaScript to call an API like Web services, listdata.svc, the JSOM, or _api (new in SP 2013). But honestly the calculated column seems to be the most solid and straightforward approach.

You can add a Content Editor webpart to your view form using SharePoint Designer and put in some jQuery to filter the list based on a querystring value.
Upload the jQuery files to your style library and add the javascript to your content editor webpart.
note that it will be hard to get this right as the querystring is extensivley used in views and views are very flexible and allow someone to completely redesign the output html, just by adding in a group by clause to the view or even remove your title field.

Related

Get listitems from Current Site

I am trying to create a Page Layout, that should have a lookup field. Lookup field should always get populated with a list's items.
This list will exist in all subsites, so whereever I create this page, list should get populated with listitems from current site.
I tried using site column lookup field, but it always point to list under top site and not the current site.
Any suggestion on how to make it work or better alternative? Thanks!
Let me know if I can provide more info.
The most straightforward solution I can think of is using a cross site lookup column and creating a seperate fields for each subsite. However, you will need to create and use different Page Layouts for each subsite.
You can use http://sp2010filteredlookup.codeplex.com/ for cross site lookups.
Solution 1 - Use http://sp2010filteredlookup.codeplex.com/
Use filtered lookup solution. So let's say you have your custom Page Layout and custom Page Content Type.
Every time you create new subsite, you should remember go to Pages list settings and edit Page Content Type by adding cross site lookup (with the same field "internal name").
So you still have one Page Layout (and one Content Type). But for each Pages library instance, Content Type contains diff fields (but with the same Internal Name). It will allow you run CAML queries and other things needed without any problems.
Solution 2 - develop custom sharepoint field type.
In edit mode, control will render "dropdown list" and populate data from list instance that is on current subsite. In the field settings you can have relative list url.
Solution 3 - hidden text field / js snippet solution
Page Content Type can contain hidden text field (it can contains selected field value in json format for example). Develop js snippet that will handle all the logic (rendering in edit/view mode, saving etc) and put it on Page Layout (aspx).
I would suggest to use solution #1 or #2.

finding client ID's of table of listview webpart

short: A listview webpart contains a table with an ID composed of two GUID's, how do I find these?
I am working on adding some additional behaviour to a standard sharepoint listview-webpart.
Preferably I don't want to actually edit the webpart itself. I want to put javascript in a helper webpart to add some onclick events to the table rows which pass the values of the id and status columns to the helper webpart, which then displays some buttons depending on the row's status.
I searched around to see how others tackled this problem, and usually they use the webpart container div with ID WebPartWPQ _n_". The problem is that these webparts are going to be used on lots of sites, and I have no way of knowing the value of _n_.
A bit further down in the hierarchy is the main table of the view, and it also has an ID. In my test-case: {BF3FB0FA-7E7F-4920-A326-B5E46826B693}-{BD0777BD-455D-4554-A80E-8A11D990D1A5}
I figured these two guids must stand for something and could possibly be looked up.
So I went on a search through Sharepoint Manager to try to find those GUIDs, but I can't find them. Neither is the list ID, nor the original View ID, nor the web ID or the site ID.
So my question: Does anybody know what these ID's stand for, and how I can find them with my webpart code?
Have you considered using XSLT to customize the output of the webpart? You could then customize the output HTML and include any identifiers you wish so that you could reference them in your javascript. This is a pretty good description of how to do this: Overriding the presentation of an XSLT List View Web Part.

Content Query Web Part and Deleted Occurrences of Events

I have a content query web part showing 3 events for todays date on our Intranet homepage. However, when a user deletes an event from a recurring series, SP changes the title of that event to "Deleted: [original title]". My content query web part still shows these and I don't see a way to filter them out.
For my list views I get around it with a field and a formula in that field of the following.
=IF(ISNUMBER(FIND("Deleted:",Title)),"Yes","No").
However, that field isn't available to me within the CQWP filter drop-down.
how does one prevent these deleted occurrences from showing in a CQWP?
UPDATE: This is a publishing page BTW.
While you can perform the filter via XSLT, it may be preferable to do so in the CAML query itself. This article from Microsoft, How to: Customize the Content Query Web Part by using Custom Properties, shows how the CAML Where clause is constructed (and may be modified). Good luck!
Have you tried the DataFormWebPart (DFWP) before? It is basically the most basic of databound webparts, but strangely the most customizable as well.
To try it out, open SharePoint designer and create a dummy aspx page to work on / play around with. Then open the datasources pane and find the list you want to use. then click on that list and select "view data". Drag the appropriate fields onto the aspx page. You now have a (very) basic grid displaying your data.
The cool thing is though, all layout is xsl driven, so completely customizable. You can even make the xsl reusable by switching to source view and cut and paste the xs,l into a separate xsl file. To then use this file instead of the inline xsl, after moving the inline xsl, change the DFWP property xsl (that contained the inline xsl) from
<xsl><!-- .... this is where the moved inline xsl used to be... --></xsl>
to
<xsllink>/server relative url to xsl file</xsllink>
The only remaining problem is that the DFWP's datasource is now bound a single list. To do roll-ups cross site collection (if you have say multiple event lists you want to include), you need to change the DFWP's SPDataSource's select query and datasourcemode. How to do that is explained here.
Now to address your actual question: (after my blatant plug of the underappreciated DFWP :-D) The DFWP's SPDataSource basically uses either an SPQuery or an SPSiteDataQuery (depending on the datasourcemode) to retrieve the data, and you can do way more filtering wise. Either in the CAML query itself or by just filter out the unneeded rows using something like the following:
<xsl:if test="not(contains(#Title, 'Deleted:'))">
<xsl:apply-templates />
</xsl:if>

Filter a Content Query Web Part using the values of another web part on the same page

I have a Content Query Web Part on my page that rolls up all the contacts lists from all the sub-webs in my site collection. this works fine. I'd like to be able dynamically filter the contacts rollup by having the user click on a list of leters of the aphhabet at the top of the page. click A and see the contacts that start with A, etc...
I'm plopping various filter web parts on the page, but don't see how to filter the results of the CQWP. The connections menu is not much help.
You can't use the OOB filter webparts or CQWP like that.
What you can do is extend the CQWP and add some functionality to it - take a look at Enhanced Content Query Web Part over at codeplex.com for inspiration.
Then send the clicked letter to the QueryString and have your extended CQWP read the filter value from the querystring - this would perform really well
Generally, this sort of thing requires some development. Here's one source:
http://www.andrewconnell.com/blog/archive/2008/02/18/Subclassing-the-Content-Query-Web-Part-Adding-Dynamic-Filtering.aspx
i would not recommend you to use a cqwp....instead try using a dataview web part it allows you to filter the content using querystring parameters without coding.

Placing Share Documents subfolder as a webpart in SharePoint

I want to place a Webpart on a page that holds a subfolder of the Document Library in SharePoint, but somehow, the only thing I get is the root folder of the document library.
Is there a Webpart that fills this need?
Here is how to do it in Sharepoint 2010 with only Javascript, no SharePoint Designer necessary.
create a document library web part on your web part page
change the view to show all items without folders and set the item limit to a sufficiently large number so that there are no batches
add Content Editor web part below document library web part
Add the following javascript and change the the first variable to meet your needs
Note: If you have more than one Document Library web part, you will need to add to this code.
<script type="text/javascript" language="javascript">
//change this to meet your needs
var patt = /FOLDER%20TO%20SEARCH/gi;
var x = document.getElementsByTagName("TD"); // find all of the TDs
var i=0;
for (i=0;i<x.length;i++)
{
if (x[i].className =="ms-vb-title") //find the TDs styled for documents
{
var y = x[i].getElementsByTagName("A"); //this gets the URL linked to the name field
//conveniently the URL is the first variable in the array. YMMV.
var title = y[0];
//search for pattern
var result = patt.test(title);
//If the pattern isn't in that row, do not display the row
if ( !result )
{
x[i].parentNode.style.display = "none"; //and hide the row
}
}
}
</script>
By default I don't think that is possible.
The list web part that would show the Shared Documents understands how to render the library, but doesn't understand how to filter to only show the contents of one subfolder.
It would be nice to create a Filter Web Part and to provide that filter to the List web part so that it filters according to the sub folder defined within the fileref field of the document library. However the filters it appears to be able to consume are Type, Modified and Modified By. So you could filter it to just the documents you touched, but not the ones in a given location.
End result: Roll your own web part.
The reason is that the folder selected by the webpart is not controlled by the webpart itself, but by a querystring parameter.
e.g.
"?RootFolder=%2fDocuments%2fMyFolder1&FolderCTID="
So folders are not "real" folders as such, despite the "lie" that is the webdav interface
e.g. \\sharepointsite\documents
There should be a way of including the desired RootFolder parameter, like a linking to the page with the querystring included (far from ideal).
I do not know of any webparts that do this.
I was able to do this by creating a new Column and specifying a keyword for the entire Shared Documents list.
Then I had to add metadata.
Add the WebPart again to the page.
Create a View that enabled the display of the files as a flat list, and filter on the new Column (i.e. where Keyword is/contains ----).
Then I get the list I want on the page with the web part.
I have a work around I've used that doesn't required Designer. Not as elegant, but achievable by any power user.
After you've added the library web part, go to the page and click down to the folder you want to be the default. See that the page link now shows something like :
www.mysite.com/sharepoint/default.aspx?RootFolder=%2Fsubfoldername&FolderCTID=...
Copy that link. Delete &FolderCTID and everything that follows. In this case what remains is :
www.mysite.com/sharepoint/default.aspx?RootFolder=%2Fsubfoldername
Use this link for navigation to the page and the library will display as you want within that page. Be aware it does not replace the default view for that page.
Another way of face this issue would be to just use the Content Search WebPart ( CSWP ) and filter the results based on :
folder path
url depth
You will need a UrlDepth value that matches your requirement. The best thing is to use a high value, like 10, and then reduce until it shows just the files you need.
Regarding folder path, remove the (quotes) ", this way the query will perform a "contains" lookup, instead of "equal to":
Result will be something like this:
path:[your site]/Docs/our_team UrlDepth:7
If the folder name contains spaces, you may need to wraps it with quotes. something like:
path:[your site]/Docs/"our team"
One alternative I've used is to drop a Page Viewer Web Part on the page and choose "Folder" as the type of thing to view. Then specify the webdav UNC to the folder such as "\some_sharepoint-site\some_site\shared documents\some_folder\"
Place the document library list view web part on any page.
Edit the web part.
From filter select column "Content Type" and value "Folder"
Save and you are done.
By doing that it will show you root folder files only.

Resources