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

How to access GridBoundColumn by DataField?

2 Answers 311 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 14 Nov 2012, 03:25 PM
I need to update one row of RadGrid after ajax call.
I get correct dataItem by rowIndex:
var dataItem = $find("<%= MyGrid.ClientID %>").get_masterTableView().get_dataItems()[radGridRowIndex];

But then it's a total mess!
I have tried a lot of ways to get correct cell to update its value, but in vain:
<telerik:GridBoundColumn HeaderStyle-CssClass='GridHeaderGreen la gridBottomHeaderGreen' ItemStyle-CssClass='la' DataField="CounterName" HeaderText="Performance counter" />

dataItem["CounterName"]
dataItem.get_dataItem()["CounterName"]
dataItem.CounterName
dataItem.get_dataItem().CounterName

I have also tried to use UniqueColumn name = DataField and apply get_cell method, but also in vain.

I can use GridTemplateColumn instead, but it will generate more markup (will add span inside td), I wanted to avoid this.

p.s. Had to use UniqueColumnName everywhere. And did
$($find("<%= MyGrid.ClientID %>").get_masterTableView().getCellByColumnUniqueName(dataItem, "CounterName")).text(bla-bla-bla);

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Nov 2012, 07:38 PM
Hello,

If you do not give Uniquename then it take datafield name as uniquename.

var grid = $find("<%=RadGrid1.ClientID %>");
              grid.get_masterTableView().get_dataItems()[0].get_cell("Name").innerHTML = "Your text";


<Columns>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                    </telerik:GridBoundColumn>
                     
                </Columns>

////if you have multiple column which have same DataField

var grid = $find("<%=RadGrid1.ClientID %>");
// Access column which have Name as Datafield
                grid.get_masterTableView().get_dataItems()[0].get_cell("Name").innerHTML = "Your text for first column"
 
// if you have multiple column which have same DataField then add 1,2,3....... after datafield name
 
                grid.get_masterTableView().get_dataItems()[0].get_cell("Name1").innerHTML = "your text for second column"


<Columns>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                    </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                    </telerik:GridBoundColumn>
 
                </Columns>


Thanks,
Jayesh Goyani
0
Alexander
Top achievements
Rank 1
answered on 21 Nov 2012, 11:54 AM
Thanks. Although by unique column name it looks more neat :) So i will stick to it...
Tags
Grid
Asked by
Alexander
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Alexander
Top achievements
Rank 1
Share this question
or