Speed / Performance

Posted by: rodrigo.oliveira on 24 June 2021, 7:55 am EST

    • Post Options:
    • Link

    Posted 24 June 2021, 7:55 am EST - Updated 3 October 2022, 1:30 pm EST

    Good Morning.

    I have performance issues. I will explain what happens.

    On the grid, I need to perform some dynamic calculations, and due to these calculations it is very slow, and even crashes the browser.

    The problem is in the format-item. It’s slow with him!

    On the console you can see the amount of times it is executed, this makes it very slow and crash! Even with this small amount of records. With a larger amount, I wouldn’t even be able to demonstrate!

    And you can see that without doing any interaction on the screen it keeps running. Would you be able to control when something changes, execute/calculate?

    Attached is part of the code.

    https://www.dropbox.com/s/6e2jrlorp7mtb68/Ticket%2020210624.wmv?dl=0

  • Posted 24 June 2021, 7:57 am EST

    Did not attach code to ticket

            <wj-flex-grid
              ref="gridDados"
              :show-selected-headers="'All'"
              :show-marquee="true"
              :sticky-headers="true"
              :items-source="dados"
              :allow-merging="'Cells'"
              :is-read-only="true"
              :alternating-row-step="0"
              :auto-generate-columns="false"
              :initialized="initializeGrid"
              :selection-changed="selectionChanged"
              :group-header-format="'<b>{value}</b> ( {count} itens )'"
    --->     :format-item="wijmoCalculoAgrupamento"
              style="width: 100%; border-radius: 0"
              class="grid"
              allow-pinning="SingleColumn"
              @mouseover.native="mouseOver"
            >
    
    
    
        wijmoCalculoAgrupamento(s, e) {
          /*
          Método para cálculo de agrupamento da grid
          */
          if (e.panel == s.cells) {
            var row = s.rows[e.row];
            var col = s.columns[e.col];
            var group = row instanceof wjcGrid.GroupRow ? row.dataItem : null;
            var CalculoPorTotais = true;
    
            var itens = 0;
            var sumVENDA_DE = 0;
            var sumVENDA_POR = 0;
            var sumVLR_CUSTO = 0;
            var calcCE113_PC_MARKUP_DE = 0;
            var calcCE113_PC_MARKUP_POR = 0;
            var calcMARGEM_LUCRO = 0;
            var calcLUCRO = 0;
            var calcLUCRO_INVERSO = 0;
            var calcLUCRO_INVERSOPERC = 0;
            var totsumVENDA_DE = this.flex.columnFooters.getCellData(0, 'ce110_vl_venda_de');
            var totsumVENDA_POR = this.flex.columnFooters.getCellData(0, 'ce110_vl_venda_por');
            var totsumVLR_CUSTO = this.flex.columnFooters.getCellData(0, 'vl_custo');
            var totsumMARKUP_DE = this.flex.columnFooters.getCellData(0, 'ce113_pc_markup_de');
            var totsumMARKUP_POR = this.flex.columnFooters.getCellData(0, 'ce113_pc_markup_por');
    
            if (CalculoPorTotais) {
              console.log("CalculoPorTotais");
              // Rodapé - https://www.grapecity.com/forums/wijmo/custom-summary#good-morning-it-worked-tha
    
              this.flex.columnFooters.setCellData(0,'ce113_pc_markup_de', ( totsumVLR_CUSTO > 0 ? (totsumVENDA_DE / totsumVLR_CUSTO) * 100 - 100 : 0));
              this.flex.columnFooters.setCellData(0,'ce113_pc_markup_por', ( totsumVLR_CUSTO > 0 ? (totsumVENDA_POR / totsumVLR_CUSTO) * 100 - 100 : 0));
              this.flex.columnFooters.setCellData(0,'lucro', totsumVENDA_DE - totsumVLR_CUSTO);
              this.flex.columnFooters.setCellData(0,'margem_lucro', (totsumVENDA_POR > 0 ? (totsumVLR_CUSTO / totsumVENDA_POR) * 100 : 0));
              this.flex.columnFooters.setCellData(0,'lucro_inverso', (totsumVENDA_POR > 0 ? (totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR : 0));
              this.flex.columnFooters.setCellData(0,'lucro_inversoperc', (totsumVENDA_POR > 0 ? ((totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR) * 100 : 0));
    
              // Cálculo das colunas agrupadas
              if (group) {
                // Captura os totais necessários para os cálculos
                for (var i = 0; i < group.items.length; i++) {
                  sumVENDA_DE += group.items[i].ce110_vl_venda_de;
                  sumVENDA_POR += group.items[i].ce110_vl_venda_por;
                  sumVLR_CUSTO += group.items[i].vl_custo;
                }
    
                if (col.binding == "ce113_pc_markup_de") {
                  if (sumVLR_CUSTO > 0) {
                    calcCE113_PC_MARKUP_DE = (sumVENDA_DE / sumVLR_CUSTO) * 100 - 100;
                  }
                  e.cell.textContent = wjcCore.Globalize.format(
                    calcCE113_PC_MARKUP_DE,
                    col.format
                  );
                }
    
                if (col.binding == "ce113_pc_markup_por") {
                  if (sumVLR_CUSTO > 0) {
                    calcCE113_PC_MARKUP_POR =
                    (sumVENDA_POR / sumVLR_CUSTO) * 100 - 100;
                  }
                  e.cell.textContent = wjcCore.Globalize.format(
                    calcCE113_PC_MARKUP_POR,
                    col.format
                  );
                }
    
                if (col.binding == "lucro") {
                  calcLUCRO = sumVENDA_DE - sumVLR_CUSTO;
                  e.cell.textContent = wjcCore.Globalize.format(
                    calcLUCRO,
                    col.format
                  );
                }
    
                if (col.binding == "margem_lucro") {
                  if (sumVENDA_POR > 0) {
                    calcMARGEM_LUCRO = (sumVLR_CUSTO / sumVENDA_POR) * 100;
                  }
                  e.cell.textContent = wjcCore.Globalize.format(
                    calcMARGEM_LUCRO,
                    col.format
                  );
                }
    
                if (col.binding == "lucro_inverso") {
                  if (sumVENDA_POR > 0) {
                    calcLUCRO_INVERSO = (sumVENDA_DE - sumVLR_CUSTO) / sumVENDA_POR;
                  }
                  e.cell.textContent = wjcCore.Globalize.format(
                    calcLUCRO_INVERSO,
                    col.format
                  );
                }
    
                if (col.binding == "lucro_inversoperc") {
                  if (sumVENDA_POR > 0) {
                    calcLUCRO_INVERSOPERC =
                    ((sumVENDA_DE - sumVLR_CUSTO) / sumVENDA_POR) * 100;
                  }
                  e.cell.textContent = wjcCore.Globalize.format(
                    calcLUCRO_INVERSOPERC,
                    col.format
                  );
                }
              }
            } else {
              // if (this.executado < 1000) {
              // this.executado += 1;
    
              console.log("CalculoPorMedia");
              itens = this.dados.totalItemCount;
    
              totsumMARKUP_DE = 0;
              totsumMARKUP_POR = 0;
              for (var j = 0; j < s.rows.length; j++) {
                if ( (group) && (this.executado < 10 ) ) {
                  this.executado += 1;
                  console.log(s.rows[j]);
                }
                totsumMARKUP_DE += s.rows[j]._data.ce113_pc_markup_de;
                totsumMARKUP_POR += s.rows[j]._data.ce113_pc_markup_por;
              }
    
              totsumMARKUP_DE = ( itens > 0 ? (totsumMARKUP_DE / itens) : 0);
              totsumMARKUP_POR = ( itens > 0 ? (totsumMARKUP_POR / itens) : 10);
    
              // Rodapé - https://www.grapecity.com/forums/wijmo/custom-summary#good-morning-it-worked-tha
              this.flex.columnFooters.setCellData(0,'ce113_pc_markup_de', totsumMARKUP_DE);
              this.flex.columnFooters.setCellData(0,'ce113_pc_markup_por', totsumMARKUP_POR);
              this.flex.columnFooters.setCellData(0,'lucro', totsumVENDA_DE - totsumVLR_CUSTO);
              this.flex.columnFooters.setCellData(0,'margem_lucro', (totsumVENDA_POR > 0 ? (totsumVLR_CUSTO / totsumVENDA_POR) * 100 : 0));
              this.flex.columnFooters.setCellData(0,'lucro_inverso', (totsumVENDA_POR > 0 ? (totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR : 0));
              this.flex.columnFooters.setCellData(0,'lucro_inversoperc', (totsumVENDA_POR > 0 ? ((totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR) * 100 : 0));
              // }
            }
          }
        },
    
    
  • Posted 28 June 2021, 8:57 am EST

    Hi Rodrigo,

    In your Code, the issue is occurred because of the setCellData method, as the setCellData method invalidates the grid after setting the value which causes the formatItem to get called in loops. To resolve the issue you need to pass false as the invalidate parameter in the setCellData method so that grid would not grid refreshed every time.

    Please refer to the API:https://www.grapecity.com/wijmo/api/classes/wijmo_grid.flexgrid.html#setcelldata

    You may also refer to the sample demonstrating the same.

    Also, I would suggest you may handle initialized event of FlexGrid as well as the cellEditEnded event and inside the handler, you may get columnFooter cell’s data using getCellData, perform calculation and then assign the calculated value to the columnFooter cell using setCellData instead of using formatItem.

    Regards,

    Ashwin

    Grid_Aggregation_Vue.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels