如何为筛选数据执行客户端分页

时间:2011-05-02 12:16:41

标签: yui-datatable

YAHOO.util.Event.addListener(“genes”,“change”,function(e){         var value = YAHOO.util.Event.getTarget(e).value;              if(YAHOO.lang.isValue(value)){             myDataTable.getDataSource()。sendRequest(null,{                 success:function(request,response,payload){                     this.initializeTable();

                var rs = response.results;
                var filtered = [];
                for(var i = 0; i < rs.length; i++) {
                      //alert(rs[i].gene);
                    if(rs[i].gene == value) {
                        filtered[filtered.length] = rs[i];
                    }
                }
                this.getRecordSet().setRecords(filtered, 0);
                this.render();
            },
            scope:myDataTable,
            argument:null
        });
    }
});

这是我过滤数据的代码。当我更改选择选项时,我正在获得完美的数据。 但是,即使显示记录,分页也不起作用,它显示为“0”。

任何人都可以建议我。

谢谢!

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

dobMenuButton.subscribe("selectedMenuItemChange",function(e) {
  var value =e.newValue.value;
  if(YAHOO.lang.isValue(value)) {
    myDataTable.getDataSource().sendRequest(null, {
        success:function(request, response, payload) {
            this.initializeTable();
            var rs = response.results;
            var filtered = [];
            for(var i = 0; i < rs.length; i++) {
                if(((rs[i].dateOfBirth).format("MM/dd/yyyy")) == value) {
                    filtered[filtered.length] = rs[i];
                }
            }
            this.getRecordSet().reset();                                                 
            MCMPagination.paginatorvar.setTotalRecords(filtered.length,true);
            this.getRecordSet().setRecords(filtered, 0);
            this.render();
    },
    scope:myDataTable, 
        argument:myDataTable.getState()
    });
   }
 });