如何使用javascript搜索gridview中的所有记录,同时允许分页是真的 [英] How to search the all records in gridview using javascript while allow paging is true
问题描述
当gridview允许分页为真时,如何在gridview中搜索所有记录
我尝试了以下代码,它只适用于该页面
我尝试过:
函数Search_Gridview(strKey,strGV){
var strData = strKey.value.toLowerCase()。split();
var tblData = document.getElementById(strGV);
var rowData;
for(var i = 1; i< tblData.rows.length; i ++){
rowData = tblData.rows [i] .innerHTML;
var styleDisplay ='none';
for(var j = 0; j< strData.length; j ++){
if(rowData。 toLowerCase()。indexOf(strData [j])> = 0)
styleDisplay ='';
else {
styleDisplay ='没有';
休息;
}
}
tblData.rows [i] .styl e.display = styleDisplay;
}
}
How to search the all records in gridview when gridview allow paging is true
I tried the below code it will work on only on that page
What I have tried:
function Search_Gridview(strKey, strGV) {
var strData = strKey.value.toLowerCase().split(" ");
var tblData = document.getElementById(strGV);
var rowData;
for (var i = 1; i < tblData.rows.length; i++) {
rowData = tblData.rows[i].innerHTML;
var styleDisplay = 'none';
for (var j = 0; j < strData.length; j++) {
if (rowData.toLowerCase().indexOf(strData[j]) >= 0)
styleDisplay = '';
else {
styleDisplay = 'none';
break;
}
}
tblData.rows[i].style.display = styleDisplay;
}
}
推荐答案
如果您在服务器上绑定GridView (代码隐藏)然后,在启用分页时,您无法搜索记录。分页网格一次只能呈现一页数据,因此您的JavaScript无法访问它。您可能希望使用允许您执行所需操作的客户端Grid。我们的想法是从服务调用中获取所有记录(假设您使用AJAX填充网格),然后从中搜索记录,然后重建客户端GridView。
一个例子是使用bootstrap数据表:使用dataTable.js(响应)排序,搜索和分页的引导表 [ ^ ]
您可以看到现场演示这里:包含分页和搜索选项的表格演示 [ ^ ]
If you are binding your GridView at the server (code behind) then there's no way for you to search the records when paging is enabled. A paged grid will only render the data one page at a time so your JavaScript doesn't have access to it. You may want to use a client-side Grid that allows you to do what you want. The idea is to grab all the records from a service call (assuming you are using AJAX to populate your grid) and then search the records from it and then rebuild your client-side GridView.
One example is using bootstrap datatables: Bootstrap Table With Sorting, Searching and Paging using dataTable.js (Responsive)[^]
You can see the live demo here: A demo of table with pagination and search options[^]
这篇关于如何使用javascript搜索gridview中的所有记录,同时允许分页是真的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!