带选择列表的 YUI Datatable 客户端过滤器?

发布于 2024-09-11 03:26:49 字数 203 浏览 6 评论 0原文

我可以使用多个下拉菜单和分页的 YUI 数据表来过滤静态数据集的行吗?

http://www.mappingbahia.org/project/iguape_dataset.html

Can I filter the rows of a static dataset using multiple drop-down menus and a paginated YUI datatable ?

http://www.mappingbahia.org/project/iguape_dataset.html

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

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

发布评论

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

评论(1

鹿童谣 2024-09-18 03:26:49

每个 YAHOO.widget 组件,例如 YUI DataTable 使用 YUI 数据源< /a> 组件,它提供填充每个呈现的 YAHOO.widget 组件所需的数据。下面你可以看到它是如何工作的

YUI datasource

注意每个 YAHOO.widget 组件内部通过 sendRequest 方法(参见步骤 1)。现在我们看一下sendRequest签名

sendRequest(request, callback)
  • 请求

对于远程数据,此请求可以是参数/值字符串,例如“id=123&name=foo”。 对于本地数据,此请求可能是一个更简单的值,例如 123。指定参数可能无关紧要,因此该值可能只是 null

  • 回调

它只是一个JavaScript对象可以描述如下(注意每个属性)

var callback = {
    success:function(request, response, payload) {
        /*
         * successful request is performed by success property
         */
    },
    failure:function(request, response, payload) {
        /*
         * failure request is performed by failure property
         */
    },
    scope:null,
    argument:null
}

因此当每个YAHOO.widget组件通过sendRequest方法调用内部YUI数据源时,它会传递一个内置回调对象,如上所示 负责渲染 YAHOO.widget 组件本身。因此,如果您想要自定义行为,您需要调用底层 YUI 数据源并传递您的自定义回调对象来过滤 YUI 数据源提供的数据,如下所示

var datatable = // YUI datatable settings goes here

要将每个更改事件附加到每个选择,您可以使用

YAHOO.util.Event.addListener("sex", "change", function(e) {
    var value = e.getTarget(e).value;

    if(YAHOO.lang.isValue(value)) {
        /**
          * Notice i am retrieving The underlying datasource To make a call To sendRequest method
          */
        datatable.getDataSource().sendRequest(null, {
            success:function(request, response, payload) {
                /**
                  * because scope property (see bellow) refers To The datatable
                  * this keyword can be used To get a reference To The datatable
                  */

                /**
                  * initializeTable method clear any data stored by The datatable
                  */
                this.initializeTable();

                var rs = response.results;
                var filtered = [];
                for(var i = 0; i < rs.length; i++) {
                    /**
                      * Is The sex property equal To The value selected by The user ?
                      */ 
                    if(rs[i]["sex"] == value) {
                        filtered[filtered.length] = rs[i];
                    }
                }

                this.getRecordSet().setRecords(filtered, 0);

                // Update UI
                this.render();
            },
            scope:datatable,
            argument:null
        });
    }
});

虽然未经测试,但我很确定它会正常工作。

Each YAHOO.widget component such as YUI DataTable uses a YUI DataSource component which provides data needed To populate each rendered YAHOO.widget component. Bellow you can see how it works

YUI datasource

Notice each YAHOO.widget component internally makes a call To The underlying YUI datasource Through sendRequest method (See step 1). Now let's see sendRequest signature

sendRequest(request, callback)
  • request

For remote data, this request may be a param/value string, such as "id=123&name=foo". For local data, this request maybe a simpler value such as 123. Specifying parameters may be irrelevent, so this value may be simply be null

  • callback

It is just an JavaScript object which can be described as follows (Notice each property)

var callback = {
    success:function(request, response, payload) {
        /*
         * successful request is performed by success property
         */
    },
    failure:function(request, response, payload) {
        /*
         * failure request is performed by failure property
         */
    },
    scope:null,
    argument:null
}

So when each YAHOO.widget component makes a call To The internally YUI datasource Through sendRequest method, It pass a built-in callback object as shown above which Takes care of rendering The YAHOO.widget component itself. So if you want a custom behavior, you need To make a call To The underlying YUI datasource and pass your custom callback object To filter The data provided by The YUI datasource as follows

var datatable = // YUI datatable settings goes here

To attach each change event To each select, you can use

YAHOO.util.Event.addListener("sex", "change", function(e) {
    var value = e.getTarget(e).value;

    if(YAHOO.lang.isValue(value)) {
        /**
          * Notice i am retrieving The underlying datasource To make a call To sendRequest method
          */
        datatable.getDataSource().sendRequest(null, {
            success:function(request, response, payload) {
                /**
                  * because scope property (see bellow) refers To The datatable
                  * this keyword can be used To get a reference To The datatable
                  */

                /**
                  * initializeTable method clear any data stored by The datatable
                  */
                this.initializeTable();

                var rs = response.results;
                var filtered = [];
                for(var i = 0; i < rs.length; i++) {
                    /**
                      * Is The sex property equal To The value selected by The user ?
                      */ 
                    if(rs[i]["sex"] == value) {
                        filtered[filtered.length] = rs[i];
                    }
                }

                this.getRecordSet().setRecords(filtered, 0);

                // Update UI
                this.render();
            },
            scope:datatable,
            argument:null
        });
    }
});

Althoug not Tested, i am pretty sure it will work fine.

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