Show By Category

.NET Service (1) 1909 (1) ACTV (1) adidas (47) adizero (1) Admiral (9) Airness (3) Albania (3) Algeria (3) America Mineiro (1) Angola (1) Anta (2) Argentina (2) Armenia (1) Atletico Goianiense (1) Atletico Paranaense (1) Austria (2) Authentic fit (1) Auto Generate from Access (1) Avai FC (1) avoid (2) Bahia (1) Beijing Guoan (1) Belgium (4) Benin (1) Birmingham City (1) Bolivia (1) Boot Configuration Data missing (1) Bosnia (1) Botafogo (2) Botafogo SP (1) Botswana (2) Brazil (4) Brazilian brand (15) Bulgaria (2) Burkina Faso (2) Burrda (3) Bypass traverse checking (1) Cambodia (1) Cameroon (4) Ceara (1) CEWP (2) Chapecoense (2) Chile (3) China (9) Chinese Brand (4) Chongqing Lifan Dangdai (1) Club Deportivo Universidad Catolica (1) Club Universitario de Deportes (1) Clube de Remo (1) Colombia (6) Colombian Brand (1) Congo DR (1) Congo Rep (1) Copa America (3) Corinthians (1) Coritiba (1) Costa Rica (2) Cote d'Ivoire (3) Coventry City (1) Croatia (2) Crop IFRAME (1) Cruzeiro (2) Crystal Palace (4) css (3) Cuba (1) Cyprus (1) Czech Republic (2) Deleting large libraries (2) Denmark (2) design fault (2) Diadora (1) Dragao Premium (1) eagles (1) Ecuador (3) Ecuadorian Brand (3) Egypt (1) El Salvador (1) electrical (2) electrical problems (2) electrocuted (2) England (3) Errea (3) Espanyol (1) Ethiopia (1) Euro 16 (10) Excel 2010 (3) External Content Type (1) FBT (3) FC Porto (1) Fenerbahce (1) Figueirense (1) Finland (1) Fiorentina (1) Flamengo (1) Flickering (1) Fluminense (1) football (233) Fortuna Dusseldorf (1) France (2) futfanatics.net (1) Gabon (1) Germany (1) Ghana (2) Gogoalshop (2) Goias (1) Granada CF (1) Grand Sport (2) Greece (2) Green (1) Guangzhou Evergrande (1) Guinea (1) Guinea Bissau (1) Haiti (1) Heilongjiang Lava Spring (1) Honduras (1) Hong Kong (1) Hummel (1) Hungary (1) Iceland (3) Icone Sports (2) IE Developer Tools (1) India (1) Indian Brand (1) Internal Field Names (1) Italy (2) Jako (1) Jamaica (2) Japan (1) Javascript (6) Jersey (126) Jiangsu Suning FC (1) Joma (5) Kanxa (1) Kappa (3) Kelme (4) Kenya (1) kitchen extractor fan (3) Korea (1) Laos (1) Le Coq Sportif (1) leak (2) Legea (1) Levante (1) Li Ning (3) Local Security Policy (1) Login Problem (1) Lotto (4) Lupo (2) Macron (9) Mafro (3) Mali (3) Man Utd (1) Marathon Sports (6) Marseilles (1) masterpage (1) Meizhou Hakka (1) Mexico (5) Modena Volley (1) Montenegro (1) Morocco (3) Myanmar (1) N98 (1) Naija (1) Nakal (1) Namibia (1) Napoli (1) Netherlands (1) New Balance (2) Newcastle United (2) Niger (1) Nigeria (4) Nike (32) Nike Brasil (1) Nike Brazil (1) Nike China (12) Nike South Africa (1) North Macedonia (1) Norway (1) O'Neills (1) Oldham Athletic (1) Olympikus (1) Olympique Lyonnais (1) Page Viewer WebPart (1) Panama (2) Para (1) Paraguay (2) Penalty (1) Peru (6) Picture Manager (1) Poland (2) Ponte Preta (1) Portugal (2) Portuguesa RJ (1) problem (2) Puma (46) retro (1) review (111) Romai (2) Romania (1) RT Sports (1) Russia (4) Saeta (1) Sampaio Correa (1) Santarem (1) Santos (2) Sao Paulo FC (1) Sao Raimundo (1) scam (2) Score Draw (1) Search List with Count Displayed (1) Senegal (3) Serbia (1) Server Hardening (1) SESI Sao Paulo (1) Shandong Luneng (1) Shanghai Shenhua (1) Shanghai SIPG (1) SharePoint (61) SharePoint Connect to SQL (2) SharePoint Designer (3) Shenzhen FC (1) shirt (232) Sierra Leone (1) Singaporean Brand (2) Six5Six (1) Slovakia (2) Slovenia (1) Slow right click (1) Sondico (1) South Africa (1) Spain (3) SPS Services (2) Spurs (1) SQL Server 2008 (1) SSP User Profile behaviour (1) Super Bolla (2) Sweden (2) Switzerland (2) Taubate Funvic (1) Team GB (2) techfit (8) Thai Brand (3) Thailand (2) Togo (1) Topper (4) track top (13) Travels (1) Trinidad and Tobago (1) Tunisia (3) Turkiye (1) tyro (1) UAE (1) UB (3) UB Electric (3) Ucan (1) UE Llagostera (1) Uganda (1) Uhlsport (2) Ukraine (1) Umbro (18) Umbro Brazil (6) Under Armour (3) Upload Center (1) Uruguay (1) Vasco Da Gama (1) Venezuela (1) Vietnam (1) Villa Nova (1) Villarreal (1) Vitoria (1) volleyball (6) Vozao (1) Wales (1) Warrix (1) water (2) WebClient (4) WebDav (5) West Ham (2) Where to get buy Iceland football shirt in Reykjavik (1) Win 8 (2) Windows 10 (1) Windows Scheduled Task (1) wish list (1) Workflow (1) World Cup 14 (9) World Cup 18 (5) Wuhan Zall (1) Xinjiang Tianshan Leopard (1) Xtep (1) Yanbian Funde (1) Yemen (1) Zambia (1) Zhejiang Greentown (2) Zimbabwe (1)

Wednesday, 29 October 2014

Filter On SharePoint List - When there is a Count in the View

While working on an idea of just quickly providing a filter search on a list.  I was trying to adapt this technique as passed to me from a colleague of mine

http://kongedagain.blogspot.hk/2013/10/filter-on-sharepoint-list.html

which in turn I think was adapted from the amazing SharePoint Boris site http://www.sharepointboris.net/articles/the-power-of-content-editor-webpart/3-quick-search-in-list-view/#

I was unable to get it work when the list was even grouped, aggregated with a count.

The reason was because the table structure of the HTML that SharePoint writes count is different when the list is aggregated.  There are several more <tbody> tags inside the main table "ms-listViewTable", this causes the JQuery search to fail as it cannot lock onto the correct <tbody> section.

Then came some more googling and guess what someone more amazing has come up with a solution.

http://www.bitsofsharepoint.com/ExamplePoint/Site/ListSearch.aspx

It works really well.  I have extracted the code to place into the CEWP below.

The only minor problem is after a search is done, it hides the count field box which would have been nice to show a count of all that has been filtered.  Also I know lots of people been asking if it can show items that are not on the screen, which happens when you are paging the list.  The answer is not yet, it can only filter whats been displayed on the screen.

<!-- This section covers the Configuration table. -->
<DIV id=configBox>
<TABLE class=table>
<THEAD class=thead>
<TR>
<TH class="thTop th" colSpan=2>List Filter - Configuration</TH></TR></THEAD>
<TBODY class=tbody>
<TR>
<TD class=tdOverview>Overview</TD>
<TD class=tdOverviewField>Here you can change the location of the filter box and add comments that the enduser can see.</TD></TR></TBODY></TABLE>
<TABLE class=table>
<THEAD class=thead>
<TR>
<TH class=th colSpan=2>OPTIONS</TH></TR></THEAD>
<TBODY class=tbody><!--This section outlines the options available to the enduser to change.
    The variable for the script is the derived from the value provided.
    There are 10 listed and commented out till needed.  Uncomment to use.
    Best practice is to use the Rich Text Editor to change the Option, Value
    and Help field vs editing in HTML editor.-->
<TR>
<TD class=tdOption>Option</TD>
<TD class="tdOptionField ">Filter Box Location</TD></TR>
<TR>
<TD class=tdValue>Value</TD>
<TD class=tdValueField id=option1>left</TD></TR>
<TR>
<TD class=tdHelp>Help</TD>
<TD class=tdHelpField>left, center, or right. You can set where the filter box is displayed by entering in either left, center or right.</TD></TR>
<TR>
<TD class=tdOption>Option</TD>
<TD class="tdOptionField ">Comments</TD></TR>
<TR>
<TD class=tdValue>Value</TD>
<TD class=tdValueField id=option2>Comments are optional.</TD></TR>
<TR>
<TD class=tdHelp>Help</TD>
<TD class=tdHelpField>You can add comments for the endusers who use this. Leave blank to have no comments show.</TD></TR><!--This section outlines the jQuery option.  This is required for the solution to work.
    This gives the user the ability to use the default external location or to define
    where the local copy of jQuery has been housed. -->
<TR>
<TD class=tdOption>Option</TD>
<TD class=tdOptionField>jQuery File</TD></TR>
<TR>
<TD class=tdValue>Value</TD>
<TD class=tdValueField id=jQueryJS>http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js</TD></TR>
<TR>
<TD class=tdHelp>Help</TD>
<TD class=tdHelpField>Only change this option if you want to use a local copy of the jQuery file.</TD></TR>
<TR>
<TD class="tdBBorder line" colSpan=2>---- Change only the gray boxes on this page. ----</TD></TR></TBODY></TABLE><!-- This section covers the Do Not change area. -->
<P class=line>Please do not Edit, Change or Add any information below this line.</P>
<HR>
</DIV><!-- This section covers the Solution Info table.  Recommended to change the values
     using the Rich Text Editor. -->
<DIV id=instructions style="DISPLAY: none">
<TABLE class=tableInfo>
<TBODY>
<TR>
<TD class="tdInfoOption ms-vb" colSpan=2>Click <B>Rich Text Editor</B> to change options</TD></TR></TBODY></TABLE>
<TABLE class=tableInfo>
<THEAD>
<TR>
<TH class=thInfo colSpan=2>CEWP Solution Info</TH></TR></THEAD>
<TBODY>
<TR>
<TD class="tdInfoLabel ms-vb">Title:</TD>
<TD class="tdInfo ms-vb">List Filter</TD></TR>
<TR>
<TD class="tdInfoLabel ms-vb">Details:</TD>
<TD class="tdInfo ms-vb">This solution will filter all visible items in a list.</TD></TR>
<TR>
<TD class="tdInfoLabel ms-vb">Site Name:</TD>
<TD class="tdInfo ms-vb">BitsOfSharePoint</TD></TR>
<TR>
<TD class="tdInfoLabel ms-vb">Site URL:</TD>
<TD class="tdInfo ms-vb"><A href="http://www.bitsofsharepoint.com/ExamplePoint/Site/ListSearch.aspx" target=_blank>http://www.bitsofsharepoint.com/ExamplePoint/Site/ListSearch.aspx</A></TD></TR>
<TR>
<TD class="tdInfoLabel ms-vb">Author:</TD>
<TD class="tdInfo ms-vb">Peter Allen</TD></TR>
<TR>
<TD class="tdInfoLabel ms-vb">Version:</TD>
<TD class="tdInfo ms-vb">2.3</TD></TR></TBODY></TABLE></DIV>
<STYLE>
/* This CSS section covers the Configuration table. */
#configBox   { display:none; }
.table     { margin: 1em; border-collapse: collapse; width:95%; }
.th     { padding: .3em; border: 1px #000 solid; border-bottom: 3px #000 solid; vertical-align:top; }
.tdOverview   { padding: .3em; border: 1px #000 solid; border-bottom: 1px #000 solid; vertical-align:top; width: 50px; }
.tdOverviewField { padding: .3em; border: 1px #000 solid; border-bottom: 1px #000 solid; vertical-align:top; }
.tdOption    { padding: .3em; border: 1px #000 solid; border-bottom: 1px #000 solid; vertical-align:top; width: 50px; }
.tdOptionField   { padding: .3em; border: 1px #000 solid; border-bottom: 1px #000 solid; vertical-align:top; font-weight: bold; }
.tdValue    { padding: .3em; border: 1px #000 solid; border-bottom: 1px #000 solid; vertical-align:top; width: 50px; }
.tdValueField   { padding: .3em; border: 1px #000 solid; border-bottom: 1px #000 solid; vertical-align:top; background: #DCDCDC; vertical-align:top; }
.tdHelp    { padding: .3em; border: 1px #000 solid; border-bottom: 3px #000 solid; vertical-align:top; width: 50px; }
.tdHelpField   { padding: .3em; border: 1px #000 solid; border-bottom: 3px #000 solid; vertical-align:top; }
.thTop     { font-size: 1.5em; }
.thead     { background: #6699CC; }
.tbody     { background: #CAE5FF; }
/* This CSS section covers the Do Not change area. */
.line     { text-align: center; font-weight: bold; }
/* This CSS section covers the Solution Info table. */
.tableInfo    { margin: 1em; border-collapse: collapse; width:500px; }
.thInfo    { padding: .1em; border: 1px #E6E6E6 solid; border-bottom: 3px #E6E6E6 solid; border-top: 3px #E6E6E6 solid; vertical-align:top; }
.tdInfo    { padding: .1em; border: 1px #E6E6E6 solid; border-bottom: 1px #E6E6E6 solid; vertical-align:top; }
.tdInfoOption   { padding: .1em; border: 1px #E6E6E6 solid; border-bottom: 1px #E6E6E6 solid; background-color: #E6E6E6; vertical-align:top; text-align:center; }
.tdInfoLabel   { text-align:right; font-weight:bold; width: 90px; padding : .3em; border: 1px #E6E6E6 solid; border-bottom: 1px #E6E6E6 solid; vertical-align:top; }
</STYLE>

<!-- This section checks for jQuery being loaded and if not then loads jQuery based on the option value. 
     Script provided by Paul Grenier from endusersharepoint.com-->
<SCRIPT type=text/javascript>
if(typeof jQuery=='undefined'){
 var jQPath = document.getElementById('jQueryJS').innerHTML.replace(/(<([^>]+)>)/ig,"");
 document.write('<script src="',jQPath,'" type="text/javascript"><\/script>');
}
</SCRIPT>
<!-- This section is where .js and .css files can be loaded from anywhere based on the above option setting. 
     The script was provided by JavaScript Kit at http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml-->
<SCRIPT type=text/javascript>
function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}
// To load a css or Javascript file from options follow the example below.
// You will need to identify the id of the option that has the URL.
// Then identify if it is a JavaScript (js) and a CSS (css) file.
//var srcURL = $('#lyteboxJS').text();
//var hrefURL = $('#lyteboxCSS').text();
//loadjscssfile(srcURL, "js") //dynamically load and add a JavaScript file
//loadjscssfile(hrefURL, "css") //dynamically load and addd a CSS file
</SCRIPT>
<SCRIPT type=text/javascript>
// This displays the Solution Info when the user is in Edit Page mode.
$(document).ready(function(){
 if ($("#edmc2").length > 0){
  $('#instructions').show();
  }
 });
</SCRIPT>
<SCRIPT type=text/javascript>
// This script section identifies the variables and the solution script
// Variables are commented out till needed.
var opt1 = $('#option1').text();
var opt2 = $('#option2').text();
// Below add your JavaScript or jQuery solution referencing the above variables.
$.extend($.expr[":"], {
 "containsNoCase": function(elem, i, match, array) {
  return (elem.textContent || elem.innerText || "").toLowerCase
  ().indexOf((match[3] || "").toLowerCase()) >= 0;
 }
});
$(document).ready(function() {
 // curser on search box
 $('#txtSearch').focus();

 $('#FilterList').css('text-align', opt1);
 var commentShow = opt2;
 if (commentShow !== '') {
  $('#filterOptionShow').show();
  $('#filterOptionShowComments').html(opt2);
 }
 else {
     $('#filterOptionShow').hide();
 }

 var its = $('img').is("img[src*='/plus.gif']");
 if (its === true) {
  $('#addOption').show();
 }

 // execute the search
 $('#ClickSearch').click(function() {
                 $('table.ms-summarystandardbody').addClass('ms-listviewtable');
  // hide all rows
  $("table.ms-listviewtable").children('tbody').children('tr').hide();
  // show the matching rows (using the containsNoCase from Rick Strahl)
  $("table.ms-listviewtable").children('tbody').children('tr:containsNoCase(\'' + $('#txtSearch').val() + '\')').show();
  // show the header row
  $('.ms-listviewtabletr:first').show();
  $(".ms-viewheadertr").show();
  $('#txtSearch').focus();
 });
 $("#clear").click(function() {
  resetSearch();
 });
 $('#txtSearch').keydown(function(e) {
  //alert(e.keyCode);
  if(e.keyCode == 13) {
   $('#ClickSearch').click();
   return false;
  }
 });
});
function resetSearch() {
 // clear the textbox
 $('#txtSearch').val('');
 // show all table rows
 $("table.ms-listviewtable").children('tbody').children('tr').show();
 // remove the cancel search image
 $('#txtSearch').focus();
}
/*
* Copyright (c) 2009 Paul Grenier (endusersharepoint.com)
* Licensed under the MIT (MIT-LICENSE.txt)
*/
$(function(){
 jQuery.groups = {
  collapse : function() {
   $("img[src*='minus.gif']:visible").parent().click();
  },
  expand : function() {
   
   $("img[src*='plus.gif']:visible").parent().click();
  }
 };
 var expandAll = "<a id='clickAll' href='#' onClick="
 +'"'+"this.href='javascript:$.groups.expand()'"
 +'">Expand All Groups</a>',
 collapseAll = "<a href='#' onClick="+'"'
 +"this.href='javascript:$.groups.collapse(),resetSearch()'"
 +'">Collapse All Groups</a>';
 $("span#optionList1").append(expandAll);
 $("span#optionList2").append(collapseAll);
});
</SCRIPT>
<STYLE>
#FilterList   { text-align:right; }
.filterHeader   { font-weight:bold; text-align:right; vertical-align:middle; }
.filterTR     { padding: 2px; }
.filterBold   { font-weight:bold; }
.filterOption  { font-size: xx-small; }
#filterOptionShow { display: none; }
#addOption   { display: none; }
</STYLE>
<DIV id=FilterList>
<TABLE id=tableFilterList style="WIDTH: 500px" cellSpacing=0 cellPadding=0>
<TBODY>
<TR class=filterTR>
<TD class="filterHeader ms-vb" valign="bottom"><NOBR>Quick Staff Name Search:</NOBR></TD>
<TD class=ms-vp><INPUT id=txtSearch maxLength=70 size=25 name=txtSearch>&nbsp;<a href="#" id=ClickSearch>Filter List</a> | <a href="#" id=clear>Clear Filter</a></TD></TR>
<TR class=filterTR id=addOption>
<TD class="filterHeader ms-vb">Option:</TD>
<TD class=ms-vp><SPAN class=filterBold id=optionList1></SPAN><SPAN class=filterOption>&nbsp;&nbsp;(Click to Filter All Grouped Items)</SPAN><BR><BR><SPAN class=filterBold id=optionList2></SPAN><SPAN class=filterOption>&nbsp;&nbsp; (Click to Reset and Collapse List)</SPAN></TD></TR>
<TR class=filterTR id=filterOptionShow>
</TR></TBODY></TABLE></DIV>

No comments:

Post a Comment