Home Web Front-end JS Tutorial A sentence of code based on JQuery to implement simple filtering of tables_jquery

A sentence of code based on JQuery to implement simple filtering of tables_jquery

May 16, 2016 pm 06:22 PM
jquery filter

效果图:
A sentence of code based on JQuery to implement simple filtering of tables_jquery
代码:

复制代码 代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JqueryTableFilter.aspx.cs" Inherits="JqueryTableFilter" %>











DataKeyNames="OrderID" DataSourceID="SqlDataSource1"
HorizontalAlign="Left" PageSize="50" >

SortExpression="OrderID" InsertVisible="False" />
SortExpression="CustomerID" />
SortExpression="EmployeeID" />
SortExpression="OrderDate" />
SortExpression="RequiredDate" />
SortExpression="ShippedDate" />
SortExpression="ShipVia" />
SortExpression="Freight" />


ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT top 50 * FROM [Orders]">





 
JQuery代码就:
复制代码 代码如下:

$(function() {
$("#Text1").keyup(function() {
var filterText = $(this).val();
$("#<%=GridView1.ClientID %> tr").not(":first").hide().filter(":contains('" filterText "')").show();;
}).keyup();
});


里面最重要的就是JQuery的选择器:

1:$("#<%=GridView1.ClientID %> tr")选择表格的所有行;
2:not(":first"):除去第一行表头行;
3:filter(":contains('" filterText "')"):从上面所选择的行里面筛选出行文本中包含filterText 的行显示出来;
4:最后加一句keyup()是为了在提交后重新触发keyup事件。(但是在这里没有作用因为我用的客户端控件没有ViewState
若是服务器端控件就会看见他的作用)。

JQuery的选择器的强大之处,让我们能救这么简单的实现客户端的简单筛选。最后加一句关于表格筛选有JQuery插件提供
给我们选择, 但是这种简单的功能,我不会去选择加入一个JavaScript文件库,呵呵。
作者:破  浪
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to filter more than 3 keywords at the same time in excel How to filter more than 3 keywords at the same time in excel Mar 21, 2024 pm 03:16 PM

Excel is often used to process data in daily office work, and it is often necessary to use the &quot;filter&quot; function. When we choose to perform &quot;filtering&quot; in Excel, we can only filter up to two conditions for the same column. So, do you know how to filter more than 3 keywords at the same time in Excel? Next, let me demonstrate it to you. The first method is to gradually add the conditions to the filter. If you want to filter out three qualifying details at the same time, you first need to filter out one of them step by step. At the beginning, you can first filter out employees with the surname &quot;Wang&quot; based on the conditions. Then click [OK], and then check [Add current selection to filter] in the filter results. The steps are as follows. Similarly, perform filtering separately again

What should I do if there is data in the Excel table but the blanks are filtered? What should I do if there is data in the Excel table but the blanks are filtered? Mar 13, 2024 pm 06:38 PM

Excel is a frequently used office software. Many users record various data in the table, but the table clearly contains data and is blank when filtering. Regarding this problem, many users don’t know how to solve it. It doesn’t matter. , the content of this software tutorial is to provide answers to the majority of users. Users in need are welcome to check out the solutions. What should I do if there is data in the Excel table but the blanks are filtered? The first reason is that the table contains blank rows. We want to filter all people with the surname "Li", but we can see that the correct results are not filtered out because the table contains blank rows. How to deal with this situation? Solution: Step 1: Select all content and then filter. Press c

How to filter duplicate content in word How to filter duplicate content in word Mar 19, 2024 pm 07:01 PM

When it comes to filtering duplicate content, the first thing you may think of is filtering numerical values ​​in Excel. In fact, in Word, we can also filter duplicate text in documents. When you are not sure whether you have typed a word incorrectly, you can use the filter to take a look. This step is very convenient. The editor below will lead you to learn how to filter duplicate content in Word. Friends who want to learn, come and study hard! 1. First, we open the word document we want to filter on the computer, as shown in the figure below. 2. Then, we select the text we want to find, as shown by the red arrow in the picture below. 3. Press [ctrl+H] on the keyboard to bring up the find and replace command. The red arrow in the figure below points to the

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

How to set up and operate wps filtering? How to set up and operate wps filtering? Mar 20, 2024 pm 09:51 PM

When using WPS tables, we sometimes list all types of data in a table. If necessary, we have to select the data that meets the requirements for application. Selecting bit by bit greatly reduces work efficiency. If you can It is much more convenient to use some software functions to make selections. The wps filtering function can realize this operation. Let’s take a look at the operation sharing below. 1. First open the data that needs to be filtered on the computer (as shown below) 2. First select the table header and click &quot;Start&quot; (as shown below). 3. Then click “Filter” (as shown below). 4. Then you will find an inverted triangle behind the table header. Click on the inverted triangle behind &quot;Math&quot; (as shown below). 5. Then the filtering options will pop up, such as clicking &quot;Number Filter&quot;

The solution to the problem that Excel tables cannot be filtered The solution to the problem that Excel tables cannot be filtered Mar 14, 2024 am 10:20 AM

In daily life, I find that the Excel table cannot be filtered, what should I do? Excel is one of the most commonly used data processing tools, helping users to complete data entry and organization simply and quickly. In order to allow users to use Excel smoothly, let's take a look at the solutions to the problem that Excel tables cannot be filtered. 1. First open the Excel document and click the [View] option in the menu. 2. Click the [Freeze Window] option in the toolbar. 3. Then in the options that open, cancel the freeze setting. 4. You can re-screen after canceling.

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

See all articles