Hi,
I'm trying to show the value of a hidden column when the row is selected. I know hidden cols value can be accessed by dataSource.view. How can I do something like:
alert(this.dataSource.view()[this.select().index()]);
where do I specific the index or field title I want to access, and how do I get it to return a string?
Thanks
I'm trying to show the value of a hidden column when the row is selected. I know hidden cols value can be accessed by dataSource.view. How can I do something like:
alert(this.dataSource.view()[this.select().index()]);
where do I specific the index or field title I want to access, and how do I get it to return a string?
Thanks
5 Answers, 1 is accepted
0
Hi Jack,
Rosen
the Telerik team
Please take a look at this jsFiddle sample which demonstrates a basic implementation of such functionality.
All the best,Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

jack
Top achievements
Rank 1
answered on 23 Nov 2011, 03:25 AM
Thank you,
I tried that example and it worked, however if a specific col (like in your example from jsFiddle) such as "UnitPrice" is not displayed as one of the columns am I still able to access that data? If so how? I tried modifiing removing "UnitPrice" and forcing the col to [3]
columns: ["ProductID", "ProductName"],
change: function() {
var cell = this.select(),
cellIndex = cell.index(),
column = this.columns[3],
dataSource = this.dataSource,
dataItem = dataSource.view()[cell.closest("tr").index()];
console.log(dataItem[column.field]);
}
I tried that example and it worked, however if a specific col (like in your example from jsFiddle) such as "UnitPrice" is not displayed as one of the columns am I still able to access that data? If so how? I tried modifiing removing "UnitPrice" and forcing the col to [3]
columns: ["ProductID", "ProductName"],
change: function() {
var cell = this.select(),
cellIndex = cell.index(),
column = this.columns[3],
dataSource = this.dataSource,
dataItem = dataSource.view()[cell.closest("tr").index()];
console.log(dataItem[column.field]);
}
0

jack
Top achievements
Rank 1
answered on 23 Nov 2011, 03:33 AM
As a follow up, I can access a column even if it's hidden. However this code some how gives me the "UnitPrice" based on what COL I am in not the ROW. Ever cell in col 1 gives 18.000 and every cell in col 2 givens 19.000
$("#grid").kendoGrid({
dataSource: {
type: "odata",
pageSize: 10,
serverPaging: true,
transport: {
read: "http://services.odata.org/Northwind/Northwind.svc/Products"
}
},
selectable: "cell",
pageable: true,
columns: ["ProductID", "ProductName"],
change: function() {
var dataItem = this.dataSource.view()[this.select().index()];
alert(dataItem.UnitPrice);
}
})
$("#grid").kendoGrid({
dataSource: {
type: "odata",
pageSize: 10,
serverPaging: true,
transport: {
read: "http://services.odata.org/Northwind/Northwind.svc/Products"
}
},
selectable: "cell",
pageable: true,
columns: ["ProductID", "ProductName"],
change: function() {
var dataItem = this.dataSource.view()[this.select().index()];
alert(dataItem.UnitPrice);
}
})
0
Hello Jack,
All the best,
Rosen
the Telerik team
The behavior you have described is caused by the fact that you are passing an incorrect index. Although, your code will work in row selection mode, when in cell selection mode you should get the row index from the cell as shown in the sample I have provided previously.
$(
"#grid"
).kendoGrid({
dataSource: {
type:
"odata"
,
pageSize: 10,
serverPaging:
true
,
transport: {
}
},
selectable:
"cell"
,
pageable:
true
,
columns: [
"ProductID"
,
"ProductName"
],
change:
function
() {
var
dataItem =
this
.dataSource.view()[
this
.select().closest(
"tr"
).index()];
alert(dataItem.UnitPrice);
}
}
All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

jack
Top achievements
Rank 1
answered on 23 Nov 2011, 12:48 PM
Got it, thanks for your help!