How to use jquery to implement simple filtering of tables

Source: Internet
Author: User


Let's take a look at how to use jquery to achieve a simple selection of the table.

1:$ ("#<%=gridview1.clientid%> tr") selects all rows of the table;
2:not (": First"): Remove the header row;
3:filter (": Contains (' + FilterText + ')"): From the selected line above, filter the rows that contain filtertext in the travel text display;
4: Add the last sentence KeyUp () to trigger the KeyUp event after the commit. (But it doesn't work here because the client control I'm using has no viewstate
If the server-side control will see his role.

The power of the jquery selector allows us to save simple filters that implement the client. Finally add a sentence about table filter There are jquery plug-ins available

Let's take a look at how to use jquery to achieve a simple selection of the table.

$ (function () {
$ ("#text1"). KeyUp (function () {
var FilterText = $ (this). Val ();
$ ("#<%=gridview1.clientid%> tr"). Not (": a"). Hide (). Filter (": Contains (' + FilterText + ')"). Show ();
}). KeyUp ();
});

Front Code

<%@ page language= "C # autoeventwireup=" true "codefile=" jquerytablefilter.asp tutorial X.cs "inherits=" Jquerytablefilter "%>
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://mb.111cn.net/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<title></title>
<script src= "script/jquery-1.3.2-vsdoc. Web Effects" type= "text/Web Effects" ></script>
<script type= "text/web Effects" >
$ (function () {
$ ("#text1"). KeyUp (function () {
var FilterText = $ (this). Val ();
$ ("#<%=gridview1.clientid%> tr"). Not (": a"). Hide (). Filter (": Contains (' + FilterText + ')"). Show ();
}). KeyUp ();
});
</script>
<body>
<form id= "Form1" runat= "Server" >
<div style= "width:60%;" >
<input id= "Text1" type= "text"/>
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "false"
datakeynames= "OrderID" datasourceid= "SqlDataSource1"
Horizontalalign= "left" pagesize= ">"
<columns>
<asp:boundfield datafield= "OrderID" headertext= "OrderID" readonly= "true"
sortexpression= "OrderID" insertvisible= "false"/>
<asp:boundfield datafield= "CustomerID" headertext= "CustomerID"
sortexpression= "CustomerID"/>
<asp:boundfield datafield= "EmployeeID" headertext= "EmployeeID"
sortexpression= "EmployeeID"/>
<asp:boundfield datafield= "OrderDate" headertext= "OrderDate"
sortexpression= "OrderDate"/>
<asp:boundfield datafield= "RequiredDate" headertext= "RequiredDate"
sortexpression= "RequiredDate"/>
<asp:boundfield datafield= "ShippedDate" headertext= "ShippedDate"
sortexpression= "ShippedDate"/>
<asp:boundfield datafield= "ShipVia" headertext= "ShipVia"
sortexpression= "ShipVia"/>
<asp:boundfield datafield= "Freight" headertext= "Freight"
sortexpression= "Freight"/>
</columns>
</asp:gridview>
<asp:sqldatasource id= "SqlDataSource1" runat= "Server"
connectionstring= "<%$ connectionstrings:northwindconnectionstring%>"
selectcommand= "SELECT Top * from [orders]" ></asp:sqldatasource>
</div>
</form>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.