在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