Is it possible to trigger an event when a row in the RadGrid is double-clicked so that I can open a pop up?
2 Answers, 1 is accepted
0
Accepted
Tsvetina
Telerik team
answered on 25 Mar 2013, 07:43 AM
Hello Blake,
You can attach the dblclick DOM event of the TR element of each row. This should be done in the databound grid event, since rows are recreated on grid refresh:
var grid = new Telerik.UI.RadGrid(document.getElementById("grid1"), {
dataSource: Sample.categories,
columns: [
{ field: "ID", width: 40 },
{ field: "Name", title: "Category" }
],
ondatabound: attachDblClick
});
function attachDblClick(e) {
var grid = e.target;
var gridElement = grid.element;
var gridRows = gridElement.querySelectorAll(".k-grid-content tr"); //(!)
for (var i = 0; i < gridRows.length; i++) {
gridRows[i].addEventListener("dblclick", function (e) {
var data = grid.dataItem(e.currentTarget);
//access data from the data item using data.[FieldName]
});
}
}
For scenarios with grouping and hierarchy you would need additional logic to select only data rows and not headers. Note the line with the (1) mark. For grouping and hierarchy scenarios it should be:
var gridRows = gridElement.querySelectorAll("tr:not(.k-header), tr:not(.k-grouping-row)");
Additionally, if you have declarative hierarchy, you should attach the databound event to each grid level:
var grid = new Telerik.UI.RadGrid(document.getElementById("grid1"), {
dataSource: Sample.categories,
columns: [
{ field: "ID", width: 40 },
{ field: "Name", title: "Category" }
],
detailTable: {
dataSource: Sample.data,
parentRelation: {
masterField: "ID",
detailField: "CategoryID"
},
columns: [
{ field: "ID", width: 40 },
{ field: "Name" },
{ field: "Price"}
],
ondatabound: attachDblClick
},
ondatabound: attachDblClick
I hope this helps.
Greetings,
Tsvetina
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.