2016-10-24 4 views
0

저는 JQGrid가 있고 그리드에 축소/모두 확장 버튼을 구현했습니다. 그것은 작동하지만 엄청나게 느립니다. 여기에 사용한 코드가 있습니다. 단 120 행만 5-6 초 걸립니다. 이 성능을 향상시킬 수있는 방법이 있습니까? 미리 감사드립니다!JQGrid 모두 매우 느림

 function CollapseAll() { 
      $(".ui-icon-circlesmall-minus").trigger("click"); 
      $("#grid_toppager_left").find('.ui-icon-minus').removeClass('ui-icon-minus').addClass("ui-icon-plus"); 
     } 

     function ExpandAll() { 
      $(".ui-icon-circlesmall-plus").trigger("click"); 
      $("#grid_toppager_left").find('.ui-icon-plus').removeClass('ui-icon-plus').addClass("ui-icon-minus"); 
     } 

     var groups = []; 

     $("#grid").jqGrid({ 
        url: '@Url.Action("GetLoanReport", "Report")', 
        datatype: "json", 
        emptyrecords: "0 records found", 
        height: "auto", 
        mtype: 'POST', 
        maxHeight: maxHeight, 
        postData: { startDate: $("#startDate").val(), endDate: $("#endDate").val(), selectedStatuses: selectedStatuses, selectedProductGroups: selectedProductGroups, assignedBranchList: assignedBranchList, assignedToList: assignedToList, createdByList: createdByList, approvedByList: approvedByList, uploadedByList: uploadedByList }, 
        colNames: ['Branch', 'Status', 'Employee', 'Application ID', 'Customer Name', 'CustNo', 'Product Type', 'Description', 'Security Code', 'Final Rate', 'New Money', 'Total'], 
        colModel: [ 
         { name: 'Branch', index: 'Branch', cellattr: function() { return ' title="my custom fixed tooltip for the column"'; } }, 
         { name: 'Status', index: 'Status' }, 
         { name: 'EmplName', index: 'EmplName' }, 
         { name: 'ApplicationID', index: 'ApplicationID', sorttype: 'number', width: 125, sortable: true, formatter: createLink }, 
         { name: 'CustName', index: 'CustName', formatter: custnameFormatter, width: 200, sortable: true }, 
         { name: 'CustNo', index: 'CustNo', hidden: true, sortable: true }, 
         { name: 'ProductType', index: 'ProductType', width: 100, sortable: true, sorttype: "text" }, 
         { name: 'ProdDesc', index: 'ProdDesc', width: 250, sortable: true }, 
         { name: 'SecurityCode', index: 'SecurityCode', width: 125, sortable: true }, 
         { name: 'FinalRate', index: 'FinalRate', width: 75, align: "right", formatter: 'currency', formatoptions: { suffix: '%' }, sorttype: 'currency', sortable: true }, 
         { name: 'NewMoney', index: 'NewMoney', formatter: 'currency', align: "right", sorttype: 'currency', formatoptions: { thousandsSeparator: ",", decimalPlaces: 0, prefix: "$" }, width: 125, sortable: true }, 
         { name: 'TotalNewMoney', index: 'TotalNewMoney', formatter: 'currency', align: "right", sorttype: 'currency', formatoptions: { thousandsSeparator: ",", decimalPlaces: 0, prefix: "$" }, width: 125, sortable: true } 
        ], 
        jsonReader: { 
         repeatitems: false, 
         root: 'rowdata', 
         page: 'currpage', 
         total: 'totalpages', 
         records: 'totalrecords' 
        }, 
        loadComplete: function() { 
         WaitIndicatorClose(); 

         var reportSum = $("#grid").jqGrid('getCol', 'TotalNewMoney', false, 'sum'); 

         $("#gridPager_right").html("<div id='sumTotal'>Number of Applications: " + $("#grid").getGridParam("records") + ", Total: $" + formatMoney(reportSum, false, null, null, null, true, false) + '</div>'); 
         $("#gridPager_right").show(); 

         if (firstLoad == true) { 
          $(".ui-icon-circlesmall-plus, .ui-icon-circlesmall-minus").each(function() { 
           groups.push({ hid: $(this).closest("tr").attr("id"), collapsed: true }); 
          }); 
         } else { 
          $("#grid tr").each(function() { 
           for (var i = 0; i < groups.length; i++) { 
            if ($(this).attr("id") === groups[i].hid) { 
             if (groups[i].collapsed == false) { 
              $("#grid").jqGrid('groupingToggle', groups[i].hid); 
             } 
            } 
           } 
          }); 
         } 

         firstLoad = false; 

         $(".gridghead_0").attr("title", "Created by Branch"); 

         $(".appLink").on("click", function (e) { 
          var appID = e.currentTarget.innerHTML; 

          ConfirmBox("This will redirect you to the Application page. Are you sure?", 
            function() { 
             $.ajaxSetup({ cache: false }); 
             $.ajax({ 
              cache: false, 
              type: "Get", 
              url: "@Url.Action("VerifyAndSetApplicationID", "Application")", 
              data: { "applicationID": appID }, 
              success: function (data) { 
               if (data.Error) { 
                MessageBox(data.Error); 
               } else { 
                if (data.Success) { 
                 InitializeWriteAccess(appID); 
                } else { 
                 MessageBox(data.NotFound); 
                } 
               } 
              }, 
              error: function (xhr, status, error) { 
              }, 
              complete: function() { 
              } 
             }); 
            }, 
            function() { 
            }); 

         }); 
        }, 
        loadError: function() { 
         WaitIndicatorClose(); 
        }, 
        loadui: 'disable', 
        grouping: true, 
        onClickGroup: function (hid, collapsed) { 
         if ($(".ui-icon-circlesmall-plus").length == 0) { 
          $("#grid_toppager_left").find('.ui-icon-plus').removeClass('ui-icon-plus').addClass("ui-icon-minus"); 
         } else { 
          $("#grid_toppager_left").find('.ui-icon-minus').removeClass('ui-icon-minus').addClass("ui-icon-plus"); 
         } 

         for (var i = 0; i < groups.length; i++) { 
          if (groups[i].hid == hid) { 
           groups[i].collapsed = collapsed; 
          } 
         } 

         if (collapsed == true) { 
          $(".ui-icon-circlesmall-minus:hidden").each(function() { 
           for (var i = 0; i < groups.length; i++) { 
            if (groups[i].hid == $(this).closest("tr").attr("id")) { 
             groups[i].collapsed = true; 
            } 
           } 
          }); 
         } 

         $('#grid').trigger('reloadGrid'); 
        }, 
        groupingView: { 
         groupField: ['Branch', 'Status', 'EmplName'], 
         groupText: ['<b>{0}</b> Count: ({1})', '<b>{0}</b> Count: ({1})', '<b>Created by {0}</b> Count: ({1})'], 
         groupSummary: true, 
         groupColumnShow: false, 
         groupSummaryPos: "header", 
         groupCollapse: true 
        }, 
        loadonce: true, 
        rowNum: 10000, 
        showrownumbers: true, 
        toppager: true, 
        shrinkToFit: true, 
        pgbuttons: false, 
        pginput: false, 
        pager: gridPager 
       }); 
       $("#grid").jqGrid('navGrid', '#gridPager', { add: false, edit: false, del: false, find: false, search: false, refresh: false }); 
       $("#grid").jqGrid('navGrid', '#grid_toppager', { add: false, edit: false, del: false, find: false, search: false, refresh: false, width: 1093 }); 
       $("#grid").jqGrid('navButtonAdd', '#grid_toppager_left', { 
        caption: "Expand/Collapse All", 
        buttonicon: "ui-icon-plus", 
        onClickButton: function() { 
         if ($(".ui-icon-circlesmall-plus").length == 0) { 
          CollapseAll(); 
         } else { 
          ExpandAll(); 
         } 

         $('#grid').trigger('reloadGrid'); 
        } 
       }); 
       $("#grid").jqGrid('navButtonAdd', '#gridPager', { 
        caption: "Export to Excel", 
        onClickButton: function() { 
         fnExcelReport(); 
        } 
       }); 
      }); 
+0

jqGrid (무료 jqGrid) (https://github.com/free-jqgrid/jqGrid), 상용 [Guiddo jqGrid JS] (http : /guriddo.net/?page_id=103334) 또는 버전 <= 4.7의 이전 jqGrid? 당신이 게시하는 코드의 향이 너무 적은 정보를 제공합니다. 그리드에 120 개의 행을 모두로드 했습니까? 표를 만드는 데 사용하는 코드는 어디에 있습니까? 온라인 데모가 있습니까? 어떤 방법 으로든 저는 무료 jqGrid 4.13.4를로드하려고 시도 할 것을 권합니다. CDN ([여기] (https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs) 참조). – Oleg

+0

죄송합니다, 무료 jqGrid를 사용하고 있습니다 –

+0

어떤 버전이 있습니까? 문제를 재현하는 JavaSctript 코드 또는 데모는 어디에 있습니까? – Oleg

답변

0

내가 게시하지 않은 코드에 문제가 있다고 가정합니다.

120 개의 행 더미 데이터와 호출기의 "Expand/Collapse All"버튼을 사용하여 the demo을 만들었습니다. 현재 (4.13.4) 버전 free jqGrid을 사용합니다. 이전의 (4.13.3) 버전의 무료 jqGrid와 동일한 데모의 성능은 테스트에서와 동일합니다. 당신은 그것을 시험해보고 성과가 좋다는 것을 볼 수 있습니다.

"모두 확장/축소"버튼의 약간 수정 된 코드를 사용했지만 확장/축소의 성능에는 차이가 없어야합니다. 업데이트]

.jqGrid("navButtonAdd", { 
    caption: "Expand/Collapse All", 
    id: "expand_collapse_all", 
    buttonicon: "ui-icon-plus", 
    onClickButton: function() { 
     var gridId = this.id, icons = this.p.treeIcons, 
      $expandCollapseAll = $("#expand_collapse_all"); 
     if ($expandCollapseAll.find('.ui-icon-minus').length > 0) { 
      $expandCollapseAll.find('.ui-icon-minus') 
       .removeClass('ui-icon-minus') 
       .addClass("ui-icon-plus"); 
      $(".tree-minus").trigger("click"); 
     } else { 
      $expandCollapseAll.find('.ui-icon-plus') 
       .removeClass('ui-icon-plus') 
       .addClass("ui-icon-minus"); 
      $(".tree-plus").trigger("click"); 
     } 
    } 
}); 

:은 당신이 마지막으로 게시 onClickGrouploadComplete의 코드가 성능 문제의 출처는 사실을 알게 될 것입니다. 귀하의 경우 120 행 대신 1000 행이있는 the demo을 시도하십시오. 1000 행의 확장은 느리지 만 IE11 컴퓨터에서는 약 0.5 초, Chrome에서는 약 190 초입니다. 그것은 당신이보고 한 5-6 초가 아닙니다.

The next demo 모든 행을 확장/축소하기 전에 임시로 표를 숨긴 ​​다음 다시 표시합니다. 추가로 성능을 향상시킵니다. 마지막 데모는 Chrome에서 160 밀리 초 및 IE11에서 350 밀리 초 내 컴퓨터에서 모두 확장됩니다.

+0

확인, 그리드 전체를 추가했습니다. 그룹 배열을 사용하여 많은 작업을하고 있습니다. 내가 한 일은 각 그룹의 붕괴/확장 상태를 저장하려고하는 것이므로 그리드를 다시 정렬하면 기본적으로 모든 그룹이 축소되지 않습니다. 어쩌면 당신도 그 일을하는 더 좋은 방법을 안다. 감사! –

+0

@ MarkHighfield : 마지막 코멘트의 질문은 원래 질문과는 완전히 독립적입니다. 무료 jqGrid에서 TreeGrid를 확장/축소하는 성능입니다. TreeGrid 상태를 저장하는 방법을 설명하는 [이전 답변] (http://stackoverflow.com/a/9202378/315935)을보십시오. 한 번 더 질문의 코드를 수정 한 것을 확인합니다. 이제 TreeGrid 대신 데이터 그룹화를 사용한다는 것을 알 수 있습니다. 미안하지만 처음에는 질문을 명확하게 작성해야합니다. 나는 당신이 정말로 필요한 것을 추측하기 위해 많은 다른 데모를 만들 수 없습니다. – Oleg

+0

제 표현이 명확하지 않으면 사과드립니다. 나는 단순히 내 그룹의 확장/축소 모든 버튼의 성능을 향상 시키려고 노력하고있다. –