Use SharePoint Designer 2010 to implment a fuzzy query for SharePoint 2010 custom list

This article describes how to use SharePoint Designer 2010 to implment a fuzzy query for SharePoint custom list with with in 10 lines Javascript code.

1. Create a list for testing

 

 

2. Click the  design in SharePoint designer 2010 button

3. Edit the list view by click the all item view:

 

4. Inset two textbox and one button into the list view UI

5. Paste the follow Javascript into the code view:

<SCRIPT type=text/javascript src="http://ajax.microsoft.com/ajax/jquery/jquery-1.7.2.min.js"></SCRIPT>
<script type="text/javascript">
String.prototype.endsWith = function(suffix) {
    return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

String.prototype.IsNullEmptyOrSpace = function()
{ 
   if (this== null) return true;
   return this.replace(/\s/g, '').length == 0;
};

var searchText;
var  idText;
$(document).ready(function () {
	searchText = GetInputForIdEndWith("TextBox1");
	idText =  GetInputForIdEndWith("TextBox2");
	idText.style.display = 'none';
	var searchButton = GetInputForIdEndWith("Button1");
	alert(idText.value);
    searchButton.onclick = function()
    {
       if(searchText.value.IsNullEmptyOrSpace())
       {
          idText.value= "0";
       }
       else
       {
         idText.value = "32767";
       }
       
       return true;
    };
});

function GetInputForIdEndWith(suffix)
{
   return  $("input").filter(function() {	    
	    var id = $(this).attr('id');
	    if(id)
	    {
	        if(id.endsWith(suffix))
	            return true;
	        else
	            return false;
	    }
	    else
	    {
	       return false;
	    }
	})[0];
}

</script >

 

 

6. Set the parameters (SearchText and MinID)

 

7. Set the filters

you can check the CAML for the filter in the code view of SharePoint designer 2010

8. Save the list view, and try to use the search function:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值