jQuery 快速搜索插件修改 JSON

发布于 2024-08-11 06:23:31 字数 938 浏览 4 评论 0原文

我已经实现了 Rik Lomas 的 quicksearch 插件,我喜欢将其用于自定义 CMS 中的应用程序我正在建设。不过我想知道,因为我将在表中包含数十亿个项目,是否有一种方法可以使用 json 回调中的数据在用户搜索时填充表而不是表内容本身。

因此,当您加载页面时,事件链将如下所示:

-jQuery.getJSON 请求 -启动快速搜索并限制表中最初显示的行数 - 当用户在过滤器中进行击键时,将从 JSON 数据而不是表内容中提取新值(仍然限制表中显示的数量),并且表会更新。

我的 JSON 请求:

$.getJSON("jsonrequest.php", function(data){

    $.each(data, function(i){
        $("#result tbody").append('<tr><td>' + this.organization + '</td><td>' + this.city + '</td><td>' + this.state + '</td></tr>');
    });

});

我的快速搜索功能:

$('table#result tbody tr').quicksearch({
    position: 'before',
    attached: 'table#result',
    stripeRowClass: ['evenrows', ''],
    labelText: 'Filter Results: ',
    loaderText: '',
    delay:0,
    focusOnLoad:true
});

I've implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I'm building. I was wondering though, since I'm going to have a bizillion items in the table if there's a way to use the data from my json callback to populate the table as a user searches rather than the table contents themselves.

So when you load the page the chain of events would go something like this:

-jQuery.getJSON request
-Initiate quicksearch and limit the number of rows initially presented in the table
-As the user makes keystrokes in the filter, the new values are pulled from the JSON data rather than the table contents (still limiting the number displayed in the table) and the table is updated.

My JSON request:

$.getJSON("jsonrequest.php", function(data){

    $.each(data, function(i){
        $("#result tbody").append('<tr><td>' + this.organization + '</td><td>' + this.city + '</td><td>' + this.state + '</td></tr>');
    });

});

My quicksearch function:

$('table#result tbody tr').quicksearch({
    position: 'before',
    attached: 'table#result',
    stripeRowClass: ['evenrows', ''],
    labelText: 'Filter Results: ',
    loaderText: '',
    delay:0,
    focusOnLoad:true
});

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

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

发布评论

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

评论(1

天煞孤星 2024-08-18 06:23:31

如果这对任何人有帮助,我已经实现了 jQuery 插件 DataTables 来解决这个问题,它提供了网格功能、分页功能和一个实时过滤器。它似乎是我遇到过的最通用的网格插件,可以满足我的需求。

If this helps anyone I've implemented the jQuery plugin DataTables to solve this one, which offers grid functions, pagination and a live filter. It seems to be the most versatile grid plugin I've come across for my needs.

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