A simple selection of the table based on jquery code _jquery

Source: Internet
Author: User
Effect Chart:

Code:
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "JqueryTableFilter.aspx.cs" inherits= "Jquerytablefilter"% >
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script src= "Script/jquery-1.3.2-vsdoc.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ (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>

The jquery code is:
Copy Code code as follows:

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


The most important thing inside is the jquery selector:

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
Give us a choice, but this simple feature, I will not go to choose to join a JavaScript file library, hehe.
Author: Breakers

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.