簡體   English   中英

jqGrid addRowData減慢了進程

[英]jqGrid addRowData slowing the process

我有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進行一些進一步的更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM