javascript - jqGrid addRowData 减慢了进程

标签 javascript jquery asp.net-mvc-3 jqgrid

我有一个包含 1000 条记录的数组,我向它传递了 javascript 函数。在 jqgrid 中显示数据大约需要 20 秒。 我知道 addDataRow 方法非常慢,但我找不到任何其他替代方法。 有什么办法可以让它更快吗?

脚本:

function GetCommodityGrid(array) {

    //    alert("Methods");
    //    var rows = array;
    alert(rows.length);
    jQuery(document).ready(function () {
        jQuery("#list").jqGrid({
            // url: 'TestGrid/GridData',
            datatype: 'local',
            //        
            colNames: ['COM_NAME', 'COM_CODE', 'DELV_UNITS', 'LOT_SIZE', 'TICK_SIZE', 'TICK_VALUE'],
            colModel: [
        { name: 'COM_NAME', index: 'COM_NAME', width: 90, editable: true },
        { name: 'COM_CODE', index: 'COM_CODE', width: 100, editable: true },
        { name: 'DELV_UNITS', index: 'DELV_UNITS', width: 80, align: "right", editable: true },
        { name: 'LOT_SIZE', index: 'LOT_SIZE', width: 80, align: "right", editable: true },
        { name: 'TICK_SIZE', index: 'TICK_SIZE', width: 80, align: "right", editable: true },
        { name: 'TICK_VALUE', index: 'TICK_VALUE', width: 150, sortable: false, editable: true }
    ],
            rowList: ReturnRowList(),
            //        loadonce: false, // hit only once on the server
            rownumbers: true, // show the numbers on rows
            pager: '#pager',
            sortname: 'COM_NAME',
            viewrecords: true, // show the total records on the end of the page
            editurl: "TestGrid/EditRecord",
            caption: "JSON Example"
        });
        for (var x = 0; x <= rows.length -1; x++) {
            $("#list").addRowData(x, rows[x]);
        }
        //   jQuery("#list").setGridParam({ rowNum: 10 }).trigger("reloadGrid");

        $("#list").jqGrid("navGrid", "#pager", { add: false },
        {   //the Edit options
            closeAfterEdit: true,
            afterSubmit: function (response) {
            // you should return from server OK in sucess, any other message on error
            alert("after Submit");
            if (response.responseText == "OKK") {
                alert("Update is succefully")
                return [true, "", ""]
            }
            else {
                alert("Update failed")
                $("#cData").click();
                return [false, "", ""]
            }
        }
    });

最佳答案

一般来说,将数组传递给 data 选项应该可以解决问题:

jQuery("#list").jqGrid({
    datatype: 'local',
    data: rows,
    ...
});

根据您的数组的外观,您可能还需要添加:

...
localReader: { repeatitems: true },
...

在极少数情况下,当您的数据非常具体(您没有将其包含在问题中)时,可能需要对 localReader 进行一些进一步的更改。

关于javascript - jqGrid addRowData 减慢了进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25448807/

相关文章:

javascript - js 或等于运算符相当于 ruby​​ 中的运算符

javascript - Jquery颜色事件问题

asp.net-mvc-3 - MVC3 razor Webgrid 分页和排序超过 2000 条记录

asp.net - 如何在 Orchard 中找到资源

jquery - Unobtrusive Ajax 在将 jQuery 更新到 1.9.0 后停止工作

javascript - CoffeeScript 编译

javascript - Nodejs解码base64并使用流将它们保存到文件中

javascript - V8(或其他 JS 引擎)BigInt 实现 - 显示为十进制

javascript - 如何使用 JS 删除内联 CSS?

javascript - 引用第 n 个选项卡单击