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

hierarchical grid expand detail row

2 Answers 833 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 23 Nov 2017, 02:13 PM
In hierarchical grid i want to expand detail row on mouse click any where on a master row instead of expand/collapse icon. may i know how i can do that?

2 Answers, 1 is accepted

Sort by
0
Accepted
Preslav
Telerik team
answered on 24 Nov 2017, 09:04 AM
Hi Muhammad,

To achieve the desired behavior use the expandRow and collapseRow methods of the Grid.
For example, in the dataBound event handler of the Grid attach click event handler to the master rows:

dataBound: function(e) {
  var grid = e.sender;
   
  grid.tbody.find("tr.k-master-row").click(function(e){                           
    var target = $(e.target);                           
    if((target.hasClass("k-i-expand"))||(target.hasClass("k-i-collapse"))){
      return;
    }         
     
    var row = target.closest("tr.k-master-row");
    var icon = row.find(".k-i-expand");
 
    if(icon.length){
      grid.expandRow(row);
    }else{
      grid.collapseRow(row);
    }   
  })
     
},

For a runnable example, check this Dojo:

Regards,
Preslav
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Muhammad
Top achievements
Rank 1
answered on 24 Nov 2017, 09:16 PM
Thanks
Richard
Top achievements
Rank 1
commented on 14 Jun 2023, 12:52 PM

That works, unless there is an edit button in the row, like this:

http://dojo.telerik.com/usEwIbEF

When you click on the edit button, the page crashes.

How to solve this?

 

Georgi Denchev
Telerik team
commented on 16 Jun 2023, 09:48 AM

Hi, Richard,

Thank you for the provided sample.

The crash isn't related to the above approach, it is a bug in the older versions of Kendo UI. You can exclude the command cell from the logic like so:

                if(target.is(".k-command-cell *")) {
                  return;
                }

However, the crash will still occur because of the bug. You can use a custom command and prevent the default behavior of the <a> element, but I'd recommend that you upgrade the library instead:

              {
                command: [{
                  name: "edit",
                  click: function(e) {
                    e.preventDefault();
                    var tr = $(e.target).closest("tr");
                    var data = this.dataItem(tr);
                    
                    $("#grid").data("kendoGrid").editRow(tr);
                  }
                }]
              }

Dojo

http://dojo.telerik.com/@gdenchev/eTomuxaH 

Best Regards,

Georgi

Tags
Grid
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Preslav
Telerik team
Muhammad
Top achievements
Rank 1
Share this question
or