HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Looping through Radgrid in JS is slow, can this be faster?

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
thisloopingcanradgridslowfasterthrough

Problem

I do a single select in one radgrid, and based upon that selection I want to select multiple rows in a different radgrid:

  ... 

    

        function RowPaymentSelected(sender, eventArgs) {
            var grid = $find("");
            var MasterTablePayment = grid.get_masterTableView();
            var paymentRow = MasterTablePayment.get_selectedItems()[0];
            var paymentCell = MasterTablePayment.getCellByColumnUniqueName(paymentRow, "DossierID")
            selectDossierRow(paymentCell.innerHTML);
        }
        function selectDossierRow(dossierID) {
            var gridDossier = $find("");
            var MasterTableDossier = gridDossier.get_masterTableView();
            var rows = MasterTableDossier.get_dataItems();

            MasterTableDossier.clearSelectedItems();
            for (var i = 0; i < rows.length; i++) {
                if (MasterTableDossier.getCellByColumnUniqueName(rows[i], "columnDossierID").innerHTML == dossierID) {
                    MasterTableDossier.selectItem(i);
                }
            }
        }

Solution

welcome to Code Review and thank you for your question. You need to profile the code to see for yourself where it is slow. Firebug and Chrome can do this. Only then will you be able to optimize your code.

Side note: Be careful about variable names, some of them seem to be in French (dossier).

Context

StackExchange Code Review Q#21384, answer score: 3

Revisions (0)

No revisions yet.