我想使用jquery将过滤器应用于我的网格。过滤器工作正常。但是当我应用分页时,过滤器不会搜索整个数据库。所以我使用ajax进行服务器端过滤这是我的jquery代码
<script type="text/javascript">
$(document).ready(function () {
$(".filtertable tr:has(td)").each(function () {
var t = $(this).text().toLowerCase();
$("<td class='indexColumn'></td>")
.hide().text(t).appendTo(this);
});
$('#<%=search.ClientID %>').keyup(function () {
var s = $(this).val().toLowerCase().split(" ");
alert("21");
$.ajax({
contentType: "application/json; charset=utf-8",
type: "POST",
data:{'prefixText':s},
//data: "{data}",
url: "AutoComplete.asmx/GetCompletionList",
//data: "{}",
dataType: "json",
success: function (data) {
for (var i = 0; i < data.d.length; i++) {
$('#<%=search.ClientID %>').append("<tr><td>" + data.d[i].group_name +
"</td><td>" + data.d[i].group_sname + "</td></tr>");
}
// $(".filtertable tr:hidden").show();
// $.each(s, function () {
// $(".filtertable tr:visible .indexColumn:not(:contains('"
// + this + "'))").parent().hide();
// });
},
error: function () { alert('Error!'); }
});
});
});
</script>
这是我的网络服务方法
public string[] GetCompletionList(string prefixText, int count)
{
//ADO.Net
SqlConnection cn = new SqlConnection();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
String strCn = "/*data connection*/";
cn.ConnectionString = strCn;
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select group_name,group_sname from group_master Where group_name like @myParameter";
cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%");
try
{
cn.Open();
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
catch
{
}
finally
{
cn.Close();
}
dt = ds.Tables[0];
//Then return List of string(txtItems) as result
List<string> txtItems = new List<string>();
String dbValues;
//String dbValues1;
foreach (DataRow row in dt.Rows)
{
//String From DataBase(dbValues)
dbValues = row["group_name"].ToString() + " " + row["group_sname"].ToString();
//dbValues1 = row["group_sname"].ToString();
dbValues = dbValues.ToLower();
//dbValues1 = dbValues1.ToLower();
txtItems.Add(dbValues);
// txtItems.Add(dbValues1);
}
return txtItems.ToArray();
}