在GridView控件过滤我已经做了在GridView中的数据filteration像数据使用jQuery
http://tomcoote.co.uk/wp-content/CodeBank/Demos/columnFilters/demo.html
此页面上。但我的要求与此有所不同。我有一个文本框外的gridview我想根据这个过滤数据。请尽快帮助我。
谢谢提前。
在GridView控件过滤我已经做了在GridView中的数据filteration像数据使用jQuery
http://tomcoote.co.uk/wp-content/CodeBank/Demos/columnFilters/demo.html
此页面上。但我的要求与此有所不同。我有一个文本框外的gridview我想根据这个过滤数据。请尽快帮助我。
谢谢提前。
如果您正在使用jQuery再考虑优秀的jQuery数据表插件,它的成效斐然,一个简单的表元素:http://www.datatables.net/
我写了下面的功能我自己,你只是把它要过滤的列索引,以及您要过滤的文本框的ID。
不要忘记到GridView /表名称更改为您的
function filter(columnIndex, id) {
var filterText = $("#" + id).val().toLowerCase();
var cellText = "";
var cellTextSampleToCompare = "";
$("#<%=YOUR_GRIDVIEW_NAME.ClientID%> tr:has(td)").each(function() {
cellText = $(this).find("td:eq(" + columnIndex + ")").text().toLowerCase();
cellText = $.trim(cellText); //removes the spaces in the starting of the string value if exist
cellTextSampleToCompare = cellText.substring(0, filterText.length);
if (filterText != cellTextSampleToCompare) {
$(this).css('display', 'none');
}
else {
$(this).css('display', '');
}
});
}
这可能不是回答你的问题,但它可能会帮助人们谁到这里来。
$(document).ready(function() {
$("#txtID").keyup(function() {
_this = this;
$.each($("#grdEmployee tbody").find("tr:has(td)"), function() {
if ($(this).text().toLowerCase().indexOf($(_this).val().toLowerCase()) != -1)
$(this).show();
else
$(this).hide();
});
});
});
作品非常感谢! – Eliseo