This is a migrated thread and some comments may be shown as answers.

Iterate all columns of a specific row client-side

2 Answers 229 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Алексей Сергеевич
Top achievements
Rank 1
Алексей Сергеевич asked on 02 Mar 2017, 06:07 PM

Hello! I create radgrid data dynamically, and i don't even know how many columns it contains and column names are unknown.

The values are simple integers. The task is to calculate the summ of cells values of specific row. How can i iterate through columns

client-side javascript ?

2 Answers, 1 is accepted

Sort by
0
Craig
Top achievements
Rank 1
answered on 03 Mar 2017, 01:25 AM

You can loop through the column collection of the GridTableView to get names and how many. From there I would think you need to find the dataItem and then sum up the value in each element.

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/gridtableview-object/gridtableview-class-members

Not simple with a dynamic grid but doable.

0
Алексей Сергеевич
Top achievements
Rank 1
answered on 03 Mar 2017, 05:45 AM

Thank You, Craig. I've done it. Just Like This

01.var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
02.var count = masterTable.get_columns().length;
03.var row = args.get_row();
04.var cells = row.cells;
05.var sum = 0;
06. 
07.for (var j = 0; j < count; j++) {
08. 
09.    var s = parseInt(cells[j].innerText);
10.     sum = sum + s;
11.  }
12.alert(sum);
Tags
Grid
Asked by
Алексей Сергеевич
Top achievements
Rank 1
Answers by
Craig
Top achievements
Rank 1
Алексей Сергеевич
Top achievements
Rank 1
Share this question
or