如何使用 jQuery DataTables 插件过滤页面加载的数据?

发布于 2024-12-28 12:11:10 字数 1486 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丘比特射中我 2025-01-04 12:11:10

正如 Datatables API 所说:

$(document).ready(function() {
    oTable = $('#example').dataTable();

    /* Filter immediately */
    oTable.fnFilter( 'test string' );
} );

如果您需要仅过滤特定列,请使用(从零开始的)columnIndex 作为第二个参数:

    oTable.fnFilter( 'test string', columnIndex );

As Datatables API says:

$(document).ready(function() {
    oTable = $('#example').dataTable();

    /* Filter immediately */
    oTable.fnFilter( 'test string' );
} );

If you need to Filter only a specific column, use (zero-based) columnIndex as second parameter:

    oTable.fnFilter( 'test string', columnIndex );
栖迟 2025-01-04 12:11:10

您可以尝试

JQuery DataTables 列过滤插件

列过滤功能是您需要使用 DataTables 站点上的自定义示例来实现的功能之一。作为替代方案,您可以使用 DataTables 列过滤器插件,其中封装了来自 DataTables 站点的大多数代码示例。

要实现和自定义列过滤,您需要使用 DataTables 插件和列过滤插件,并使用基本的 !dataTable 插件和 columnFilter 插件增强您的 HTML 表,如示例所示:

 $("#dataTableId").dataTable().columnFilter();

请参阅文本 - 默认行为。您可以定义在过滤中使用正则表达式还是智能过滤,

此处http://code.google.com/p/jquery-datatables-column-filter/wiki/ColumnFilter

请参阅了解更多详细信息http://code.google.com/p/jquery-datatables-column-filter/

实例 http://jquery-datatables-column-filter.googlecode.com/svn/trunk/default.html

编辑

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>    
<script type="text/javascript" src="Scripts/scripts-pack.js"></script>  

This plugin will then create the filters in a row in the THEAD element of the table so add this if it is not already there.


<table id='demotable'>        
    <thead>
        <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>        
    </thead>
    <tbody>
        <tr><td>Value 1</th><th>Value 2</th><th>Value 3</th></tr>        
        ....
    </tbody>
</table>

Hook in your table when the document is loaded.


$(document).ready(function() {
    $('#demotable).tableFilter();
});

参考http://www.picnet.com.au/blogs/Guido/post/2009/06/29/JQuery-Table-Filter-Plugin.aspx

you can try

JQuery DataTables Column Filtering plugin

Column filtering functionality is one of the functionalities that you will need to implement using the custom examples on the DataTables site. As an alternative you can use the DataTables Column filter plugin where most of the code exmaples from the DataTables site are encapsulated.

To implement and customize column filtering you will ned to take DataTables plugin and column filtering plugin and enhance your HTML table with basic !dataTable plugin and then with columnFilter plugin as shown in the example:

 $("#dataTableId").dataTable().columnFilter();

see text - default behavior. You can define whether the regular expression or smart filtering will be used in the filtering,

here http://code.google.com/p/jquery-datatables-column-filter/wiki/ColumnFilter

refer for more details http://code.google.com/p/jquery-datatables-column-filter/

for live example http://jquery-datatables-column-filter.googlecode.com/svn/trunk/default.html

EDIT

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>    
<script type="text/javascript" src="Scripts/scripts-pack.js"></script>  

This plugin will then create the filters in a row in the THEAD element of the table so add this if it is not already there.


<table id='demotable'>        
    <thead>
        <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>        
    </thead>
    <tbody>
        <tr><td>Value 1</th><th>Value 2</th><th>Value 3</th></tr>        
        ....
    </tbody>
</table>

Hook in your table when the document is loaded.


$(document).ready(function() {
    $('#demotable).tableFilter();
});

refer http://www.picnet.com.au/blogs/Guido/post/2009/06/29/JQuery-Table-Filter-Plugin.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文