【问题标题】:Jqgrid shows 'Loading' in IE9 when gridview is set to true当 gridview 设置为 true 时,Jqgrid 在 IE9 中显示“正在加载”
【发布时间】:2015-01-22 13:25:19
【问题描述】:

我的网格在 Firefox 和 chrome 中运行良好,但是当 gridview 设置为 true 时,它​​在 IE9 中显示“正在加载”图标。这是使用 jqgrid 4.7.0

var setGrid = $("#recordSetsGrid");
var gridView=false; //setting this to true in IE9 causes grid not to show with only message 'Loading'.

setGrid.jqGrid(
        {
            ajaxGridOptions: {cache: false},
            url : getUrlContext()+loadUrl,
            postData : {
                searchText : function() {
                    return $("#" + setSearchTextId)
                            .val();
                }
            },
            datatype : "json",
            editurl : setGrid_editUrl,
            colNames : ["","Record Set", "Origin",
                    "Origin", "Organization",
                    "Sharing", "Active?",
                    "Comments" ],
            editCaption : "Edit Record Set",
            colModel : [
                    {
                        name : "crud",
                        width : 10,
                        fixed : true,
                        editable : false,
                        search : false
                    },
                    {
                        name : "recordSet",
                        width : 65,
                        fixed : true,
                        editable : false,
                        search : false
                    },
                    {
                        name : "origin",
                        width : 90,
                        editable : true,
                        hidden : true,
                        editrules : {
                            required : false,
                            edithidden : true
                        },
                        search : true,
                        editoptions : {
                            size : "30"
                        }
                    },
                    {
                        name : "domainName",
                        width : 90,
                        editable : false,
                        search : true,
                        searchoptions : {
                            caption : "Search in record sets",
                            sopt : [ 'cn' ]
                        },
                        formatter : originFormatter,
                        editrules : {
                            required : true,
                            edithidden : false
                        }
                    },
                    {
                        name : "org",
                        width : 80,
                        align : "left",
                        editable : true,
                        search : false,
                        formatter : orgFormatter,
                        editoptions : {
                            value : orgChoices
                        },
                        edittype : "select",
                    },
                    {
                        name : "sharing",
                        width : 65,
                        fixed : true,
                        align : "left",
                        editable : true,
                        search : false,
                        editoptions : {
                            value : sharingChoices
                        },
                        edittype : "select",
                    },
                    {
                        name : "active",
                        width : 45,
                        fixed : true,
                        align : "center",
                        editable : true,
                        search : false,
                        edittype : "checkbox",
                        editoptions:{value:"Yes:No", defaultValue: "Yes"}       
                    }, 
                    {
                        name : "comments",
                        width : 80,
                        align : "left",
                        editable : true,
                        search : false,
                        editoptions : {
                            size : "60"
                        }
                    } ],
            pager : "#recordSetsGridPager",
            gridview: gridView,
            rowNum : getRecordSetInitialPageSize(),
            rowList : getRecordSetPageSizes(),
            sortname : "origin",
            sortorder : "desc",
            viewrecords : true,
            autoencode : true,
            rownumbers: true,
            height : 100,
            width : 700,
            multiselect : false,
            caption : "Record Sets",
            onSelectRow : function(ids) 
            {
                var rowData = setGrid.jqGrid("getRowData",ids);
                var origin=rowData["domainName"];
                var caption="Resource Records: "+ origin;
                if (ids == null) {
                    ids = 0;
                    if (jQuery("#recordsGrid").jqGrid('getGridParam','records') > 0) {
                        recGrid.jqGrid('setGridParam',{url:getUrlContext()+"" +
                                "/ZoneEditManaged.action?_eventName=getResourceRecords&isInit",page:1});
                        //recGrid.jqGrid('setCaption',caption).trigger('reloadGrid');
                        recGrid.trigger('reloadGrid');
                    }
                } else {
                    recGrid.jqGrid('setGridParam',{url:getUrlContext()+
                        "/ZoneEditManaged.action?_eventName=getResourceRecords&&isInit=1",page:1});
                        //"/ZoneEditManaged.action?_eventName=getResourceRecords&&isInit=1&setId="+ids,page:1});
                    //recGrid.jqGrid('setCaption',caption).trigger('reloadGrid');
                    recGrid.trigger('reloadGrid');
                }

                $("#captionOriginId").html(origin);

                //drawResourceRecordSearchBox(recGrid,caption); 
            },
            ondblClickRow : function(rowid) {
                var p = setGrid[0].p;
                if (p.selrow !== rowid) {
                    grid.jqGrid('setSelection',
                            rowid);
                }
                setGrid.jqGrid('editGridRow',
                        rowid, editProps);
            },
            loadComplete : function() {
                logMessage("In recordSetsGrid load complete");
                applyContextMenu();
                highlightFilteredData.call(this,setSearchTextId);
            },
            loadError : function(jqXHR, textStatus,
                    errorThrown) {
                handleAjaxError(jqXHR, textStatus,
                        errorThrown);
            }
        }).navGrid('#recordSetsGridPager', {
    add : true,
    edit : true,
    del : true,
    search : false
}, editProps, addProps, delProps);

如果我更改 gridView=false,它在 IE9 中运行良好。我将在这个网格中有大量数据,所以我读到 gridView=true 可以在大数据的情况下加快性能。感谢任何让 gridView 在 IE9 中工作的想法。

谢谢

【问题讨论】:

  • 您应该调试代码。只需按 IE9 的 F12 按钮启动开发工具并选择“脚本”并按“开始调试”按钮。您将在代码中准确地看到问题存在的哪里。加载网格时出错最多的原因是代码loadComplete。你在里面打电话给logMessageapplyContextMenuhighlightFilteredData。我想函数中的一些有错误。应该调试代码。
  • 我注释掉了 loadComplete 中的所有代码并再次尝试使用 gridView=true,同样的问题,网格不加载。我在“ts.firstElementChild.innerHTML += rowData.join(''); // 附加到包含第一行 (.jqgfirstrow) 的 tbody 的 innerHTML”的第 1641 行看到了 grid.base.js 中的错误。我确定我的某些配置不正确。我将从头开始编写一个新网格,看看我是否可以让它在 IE 中工作,但那是我腾出一些时间的时候。
  • 让我问你这个。我的网格中没有单元格编辑。所有编辑都使用编辑表单完成。设置 gridView=true 还能给我带来绩效奖励吗?我在文档中读到 gridView=true 加快了 ajax 编辑的性能。是指 ajax 单元格编辑还是表单编辑。

标签: javascript jquery jsp jqgrid


【解决方案1】:

@Oleg 的修改对我的类似问题很有帮助,但是我仍然在 Internet Explorer 9 中收到错误 invalid target element for this operation(在 7 中没有问题, 8, 10, 或 11) 在尝试这行代码时:

self.firstElementChild.innerHTML += rowData.join('');

但是,设置 jqGrid 属性后...

gridview: false

...我在 Internet Explorer 9 中不再出现该错误。据我了解,将 gridview 设置为 true 会立即构建表,从而提供更快的性能,而将 gridview 设置为 false 会逐行构建它并且速度稍慢.

我不知道 jqGrid 是如何将表格数据附加到 innerHTML 的,因为来自MSDN

innerHTML 属性在 col、colGroup、frameSet、html、head、style、table、tBody、tFoot、tHead、title 和 tr 对象上是只读的。

但是,即使使用 gridview:true,它在所有版本的 IE 中对我都有效,除了 IE9。

这不是一个真正的答案,但希望它可以帮助某人。一如既往,感谢@Oleg 对 jqGrid 的所有贡献。你对我的帮助超出了你的想象。

【讨论】:

    【解决方案2】:

    在您回答您的问题后,我明白了这个问题。问题的原因是 jqGrid 中的错误。它使用firstElementChild(参见the lines)属性:

    } else {
        //$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
        ts.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
        ts.grid.cols = ts.rows[0].cells; // update cached first row
    }
    

    我之前在 jqGrid 的 my fork 中修复了该错误(目前请参阅 the lines):

    } else if (self.firstElementChild) {
        self.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
        self.grid.cols = self.rows[0].cells; // update cached first row
    } else {
        // for IE8 for example
        $tbody.html($tbody.html() + rowData.join('')); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
        self.grid.cols = self.rows[0].cells; // update cached first row
    }
    

    所以我可以建议在jquery.jqGrid.src.js 中进行相同的更改,或者从my repository 下载修改后的jquery.jqGrid.src.jsjquery.jqGrid.min.jsjquery.jqGrid.min.map 文件(参见js 文件夹)。我应该警告你代码正在开发体育场,我计划在下个月发布第一个版本,但当前代码是稳定的,它包含我发现的许多其他修复和一些新功能(在自述文件中简要描述) .

    更新:上面修复问题的代码来自我的新代码,因此它包含上面在我的代码中定义的self$tbody。如果要修改 jqGrid 4.7 的代码,可以使用

    } else if (ts.firstElementChild) {
        ts.firstElementChild.innerHTML += rowData.join('');
        ts.grid.cols = ts.rows[0].cells;
    } else {
        // use for IE8 for example
        var $tbody = $(ts.tBodies[0]);
        $tbody.html($tbody.html() + rowData.join(''));
        ts.grid.cols = ts.rows[0].cells;
    }
    

    UPDATED 2: free jqGrid 的片段的当前代码如下所示

    if (p.treeGrid === true && fpos > 0) {
        $(self.rows[fpos]).after(rowData.join(""));
    } else if (p.scroll) {
        $tbody.append(rowData.join(""));
    } else if (self.firstElementChild == null || (document.documentMode != undefined && document.documentMode <= 9)) {
        // for IE8 for example
        $tbody.html($tbody.html() + rowData.join("")); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
        self.grid.cols = self.rows[0].cells; // update cached first row
    } else {
        self.firstElementChild.innerHTML += rowData.join(""); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
        self.grid.cols = self.rows[0].cells; // update cached first row
    }
    

    【讨论】:

    • 谢谢。我下载了分叉的代码并在 linux 下运行它,我意识到由于我的寻呼机按钮没有显示,并且在某些情况下我也丢失了选择状态,所以我做了很多更改。因此,我只会在星期一应用手术贴片并进行测试。周一会公布结果。再次感谢。
    • @Sannu:您能否提供重现您描述的问题的演示?您是否在代码中的某处使用了table.navgrid 选择器?如果你使用它,你应该把它替换为.navgrid。这是我在寻呼机中知道的唯一问题。您使用哪种选择模式(multiselect: true 与否)?
    • 我让它工作了,但我必须对你提供的补丁做一些更改。我收到了 'self' 的 javascript 错误,并使用以下代码进行了修复。它运行良好,但看看您是否发现此代码有任何问题。
    • @Sannu:我从 my fork of jqGrid 中加入了一些行,其中self 是之前定义的。如果你想在 old jqGrid 中使用相同的代码,你应该使用ts 而不是self。变量$tbody 只是网格var $tbody = $(ts.tBodies[0]); 的主体。表达式ts.tBodies[0] 可以非常快速地计算,但$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first") 的计算速度较慢。
    【解决方案3】:

    我将 'ts.firstElementChild' 包装到 $ 而不是 'innerHTML' 属性中。

     try {
            ts.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
         } 
     catch (e) {
            //IE 9 bug-fix for exception "invalid target element for this operation"                    
    
           $(ts.firstElementChild).html($(ts.firstElementChild).html() + rowData.join(''));
         }
    

    它正在工作。

    【讨论】:

      【解决方案4】:

      @Oleg,我不得不对您的补丁进行一些更改,因为我在“self”处遇到了 javascript 错误。我想如果我使用了完整的脚本,我猜它会起作用的。这是我修改后的代码,如果看起来不对,请告诉我。

                  } else if (ts.firstElementChild) { //Fix applied by Oleg for gridView=true in IE9.
                      ts.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
                      ts.grid.cols = ts.rows[0].cells; // update cached first row
                  } else {
                      // for IE8 for example
                      $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").html() + rowData.join('')); //Modified
                      //$tbody.html($tbody.html() + rowData.join('')); // append to innerHTML of tbody which contains the first row (.jqgfirstrow) //doesn't work.
                      ts.grid.cols = ts.rows[0].cells; // update cached first row
                  }
      

      它现在正在工作。谢谢你的帮助。明天我会用你的分叉代码测试我的网格并告诉你结果。

      【讨论】:

      • 如果您使用$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append 而不是.html,那么您应该从右侧部分删除$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").html() 并仅附加rowData.join('')。当前代码似乎添加了第一行 (tr.jqgfirstrow) 两次 这是错误的。
      猜你喜欢
      • 2023-03-27
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多