This blog will tell you how to get the title of the selected column in Kendo Grid using the column index in the change event.

kendoGrid.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Untitled</title>
  6. <style>
  7. html
  8. { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }
  9. .messageArea
  10. {
  11. margin-top:22px
  12. }
  13. #message
  14. {
  15. color:orange;
  16. }
  17. </style>
  18. <title></title>
  19. <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.common.min.css" />
  20. <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.highcontrast.min.css" />
  21. <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.highcontrast.mobile.min.css" />
  22. <script src="https://kendo.cdn.telerik.com/2018.1.221/js/jquery.min.js"></script>
  23. <script src="https://kendo.cdn.telerik.com/2018.1.221/js/kendo.all.min.js"></script>
  24. <body>
  25. <h3>Kendo Grid </h3>
  26. <div id="grid"></div>
  27. <div class="messageArea">
  28. Selected Cell Column Name : <label type="text" class="form-control" id="message">
  29. <div>
  30. <script>
  31. $(document).ready(function()
  32. {
  33. dataSource = new kendo.data.DataSource({
  34. data:[{ ProductID:1, productName: "Tea", category: "Beverages" },
  35. { ProductID:2, productName: "Coffee", category: "Beverages" },
  36. { ProductID:3, productName: "Ham", category: "Food" },
  37. { ProductID:4, productName: "Bread", category: "Food" } ],
  38. schema:{
  39. model:{
  40. id:"ProductID",
  41. fields:{
  42. ProductID:{editable:false,nullable:true},
  43. productName:{editable:true},
  44. Category:{editable:true}
  45. },
  46. }
  47. },
  48. })
  49. $("#grid").kendoGrid({
  50. dataSource: dataSource,
  51. selectable: "cell",
  52. allowCopy: true,
  53. editable:true,
  54. navigatable:true,
  55. change: onChange,
  56. columns: [
  57. { field: "productName", title:"Product Name" },
  58. { field: "category",title:"Category"}
  59. ],
  60. });
  61. });
  62. function onChange(e)
  63. {
  64. var grid = $("#grid").data("kendoGrid");
  65. var colIdx = grid.select().closest("td").index();
  66. var columnheader= this.options.columns[colIdx].title;
  67. $("#message").text(columnheader);
  68. }
  69. </script>
  70. </body>
  71. </html>

We need a column index detail to get the name of the column which is selected. We will use the change event in the grid which will trigger while the column gets selected.

  • select() will give the information about the selected cell in grid.
  • grid.select().closest("td").index() -> will give the index detail of the selected cell.
  • this.options.columns[colIdx].title -> will give the selected cell column title.
Result