【问题标题】:dojo enhanced grid server side pagination not workingdojo 增强的网格服务器端分页不起作用
【发布时间】:2019-01-01 16:06:28
【问题描述】:

我在尝试使用增强型数据网格 (dojo v1.10) 执行服务器端分页时遇到问题。 第一页正确显示,但小部件(存储?网格?插件?)似乎忽略了“Content-Range”标题值作为响应,并且不允许获取下一页。 例如,响应标头包含“Content-Range: items 0-9/17”,分页显示“1 到 10 of 10 个项目”,下一页不可用。

经过一些调试后,我看到从 JsonRest 存储(查询函数)中正确读取了范围值

    results.total = results.then(function(){
    var range = results.ioArgs.xhr.getResponseHeader("Content-Range");
    return range && (range = range.match(/\/(.*)/)) && +range[1];
    }); 
...

但在 ObjectStore 的 fetch 方法中,totalCount 值未定义,然后使用 results.length:

var results = this.objectStore.query(query, args);
        Deferred.when(results.total, function(totalCount){
            Deferred.when(results, function(results){
                if(args.onBegin){
                    args.onBegin.call(scope, totalCount || results.length, args);
...

有什么想法吗?

谢谢,

我的代码:

// get grid store
var restStore = new JsonRest(
    {
        target: "ks2/api/workflow/...",
    });
var memoryStore = new Memory();
var store = Cache(restStore, memoryStore);      

/*set up layout*/
var layout = [{
            name: "id",
            field: 'id',
            width: '5%',
            datatype:"string"
        },
        ....
    ];

/*create a new grid*/
this.workflowGridWidget = new EnhancedGrid({
        id: 'workflowGridWidget',
        store: new ObjectStore({objectStore: store}),
        structure: layout,
        rowSelector: '20px',
        plugins: {
            pagination: {
                          pageSizes: ["10", "25", "50"],
                          defaultPageSize: 10,
                          description: true,
                          sizeSwitch: true,
                          pageStepper: true,
                          gotoButton: true,
                          maxPageStep: 4,//page step to be displayed
                          position: "bottom" //position of the pagination bar
                      }
        }
    });

/*append the new grid to the div*/
this.workflowGridWidget.placeAt("workflowDataGrid");

/*Call startup() to render the grid*/
this.workflowGridWidget.startup();

【问题讨论】:

  • 尝试将defaultPageSize的值更改为更大的数字,您也应该尝试将其删除,对不起,我记不太清楚了,但几年前我遇到了一个与此相关的问题
  • 感谢您的建议,但没有效果(defaultPageSize 已删除或价值较高)
  • 您是否尝试过使用 Observable 存储而不是缓存和内存?类似于... Store = Observable( new JsonRestStore({}));

标签: datagrid pagination dojo


【解决方案1】:

我发现了问题:我使用的是非 dojo 兼容的 API,我需要添加 JSON 响应后处理使用

aspect.after(store, "query", this.processResponse);
...

processResponse: function ks2ProcessMonitor_datagrid_WorkflowDataGrid_processResponse(deferred) {
    return deferred.then(function(response) {
        //process response content
        return processedResponse;   
    });
},

这工作正常,但由于某种原因,它对分页有影响。删除这个后处理(使用另一个符合 dojo 的 API)修复了分页问题。 也许我应该按照 Layke 的建议尝试使用 Observable 进行响应后处理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    相关资源
    最近更新 更多