为什么loadComplete在gridComplete之前触发? [英] Why loadComplete fires before gridComplete?

查看:93
本文介绍了为什么loadComplete在gridComplete之前触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理在loadComplete事件中从服务器获取的数据:

I am trying to manipulate the data fetched from the server in loadComplete event:

loadComplete:function(data){
    alert("load completed");
    $.each (data,function(index,item){

    item["customerSite"]=item.header.customerName + ' / '+item.header.siteDescription;
    });
}

新添加的字段旨在用作按以下内容分组的列 但是,我一直将此列作为未定义的分组标题.我尝试将另一个字段作为常规列添加到JSON对象,该列最终为空.在调试时,我注意到在loadComplete中的断点停止之前已构建了网格.

The newly added field is meant to be used as a column to be grouped by However I keep getting this column as undefined as grouping header. I tried adding another field to the JSON object as a regular column, the column ends up to be empty. As I was debugging I noticed the grid is constructed before my breakpoint in the loadComplete stops.

我对loadComplete事件的理解是,一旦ajax调用成功返回,它将立即触发.在将gridComplete事件引入代码后,我注意到在调用loadComplete之前先调用gridComplete.

My understanding of the loadComplete event is that it will fired as soon as the ajax call has success return. After I introduced gridComplete event to my code, I noticed gridComplete is invoked before loadComplete is invoked.

gridComplete: function(){ 
    alert("grid completed");
}

我做错了什么?我正在使用

What I am doing wrong? I am using

            jsonReader: {
                repeatitems: false,
                id: "id",
                root: function (obj) { return obj; },
                page: function (obj) { return 1; },
                total: function (obj) { return 1; },
                records: function (obj) { return obj.length; }
            }

处理返回的JSON字符串,但是无法想象这可能是问题所在.请帮忙!

to process returned JSON string, but cannot imagine that might be the problem. Please help!

基于Oleg的评论,我将使用自定义格式化程序.但是,fomratter的结果不适用于该列所针对的组头.如果我将groupColumnShow设置为[true],则该列的数据都是正确的,但仍将组标题保留为'undefined'

Base on Oleg's comment, I will use custom formatter. However the result of the fomratter does not work for the group header, which this column is for. If I set groupColumnShow : [true], the column's data is all correct, but still leaves the group header to be 'undefined'

遵循网格的定义:

buildGrid:function(){
        var myGrid = jQuery("#serverList");

        myGrid.jqGrid({

        datatype: "json",
        url: "http://localhost:8080/cm.server/api/v1/agent/config.json?",
        jsonReader: {
            repeatitems: false,
            id: "id",
            root: function (obj) { return obj; },
            page: function (obj) { return 1; },
            total: function (obj) { return 1; },
            records: function (obj) { return obj.length; }
        },              
        colNames:['Customer/Site','Customer','Site','Server ID', 'Server Name', ,'id'],

        colModel :[ 
              {name:'customerSite',editable:false, formatter:that.buildCustmerSite},   
              {name:'header.customerName',hidden:true,editable:true,editrules:{edithidden:true},editoptions:{readonly:true,size:25},formoptions:{ rowpos:1,elmprefix:" "}},

              {name:'header.siteDescription', hidden:true, editable:true,editrules:{edithidden:true},editoptions:{readonly:true,size:25},formoptions:{ rowpos:2,elmprefix:" "}},         

              {name:'header.serverID', index:'header.serverID', width:200, align:'right',editable:true,editoptions:{readonly:true,size:25},formoptions:{ rowpos:3,elmprefix:" "}},

              {name:'header.serverName', index:'header.serverName', width:150, align:'right',editable:true,editoptions:{readonly:true,size:25},formoptions:{ rowpos:4,elmprefix:" "}},

              {name:'id', hidden:true},

            ],
            height: '500',
            width: '100%',
            rowNum:20,
            autowidth: true,
            pager: '#pager',
            sortname: 'serverID',
            sortorder: "desc",
            viewrecords: true,
            caption: 'Server Configurations',
            editurl:"/cm.server/api/v1/agent/config-grid",
            autoencode:true,
            ignoreCase:true,
            grouping:true,
            groupingView:{
                groupField:['customerSite'],
                groupColumnShow : [false]
            }
          });

      jQuery("#serverList").jqGrid('navGrid','#pager',
      {edit:true,add:false,del:false,search:true}, 
      {height:450,reloadAfterSubmit:true,  recreateForm:true,jqModal:true, closeOnEscape:true,  closeAfterEdit:true, bottominfo:"Fields marked with (*) are required"}, // edit options
            {} // search options
        );
      jQuery("#serverList").jqGrid('filterToolbar'); 
      return true;
    }

,以下是自定义格式程序:

and following is the custom formatter:

buildCustmerSite:function(cellvalue,options,rowObject){
    var customerSite =rowObject.header['customerName'] + '/'+ rowObject.header["siteDescription"];
    return customerSite;
}

推荐答案

loadComplategridComplete之间存在细微差别,但是在准备好网格包含之后,两者都将被称为.因此,您不能只修改loadComplatedata来更改网格包含.

There are small differences between loadComplate and gridComplete, but both will be called after the grid contain is prepared. So you can't just modify the data of the loadComplate to change the grid contain.

您没有发布网格的定义,因此很难准确回答您的问题.您可能想要解决的问题与自定义格式程序有关您可以为customerSite列定义.在格式化程序功能内,您可以访问rowObject,您可以在其中找到构建customerName +'/'+ siteDescription的源信息.

You don't posted the definition of your grid, so it is difficult to answer on your question exactly. What you probably want can be solved with respect of the custom formatter which you can define for the customerSite column. Inside of formatter function you have access to rowObject where you find source information to construct the customerName + ' / ' + siteDescription.

这篇关于为什么loadComplete在gridComplete之前触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆