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

Get dataItem of KendoGrid base grid selected row

6 Answers 5300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
FranckSix asked on 19 Nov 2019, 11:01 AM
I'm trying to encapsulate a method to retrieve the row id from my KendoGrids On every grid in my app I have a hidden column named Id. I would like to get this id from my base grid, on both master grid with childs or a grid with no childs. This is my not working method :
get idSelection() {
         var grid = $("#grid").data('kendoGrid');
         var row = grid.select();
 
         if (!row.is('.k-master-row')) {
            row = row.closest(".k-master-row");
         }
         const selected = this.grid.dataItem(row);
         return selected ? selected.Id : undefined;
      }

6 Answers, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 21 Nov 2019, 07:44 AM

Hi FranckSix,

Can you provide more details about the scenario in which you want to get the value of the hidden "id" column? To provide a relevant solution I will need to know the dependency of the Grids you mentioned. Can you create a Dojo project demonstrating the scenario in which you use the Grid/s?

Here are some examples you may find useful and may help you resolve the issue:

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 27 Nov 2019, 08:45 PM

Here a snippet of what i want:

http://dojo.telerik.com/@FranckSix/iKIsInaf

 

0
Accepted
Nikolay
Telerik team
answered on 29 Nov 2019, 03:28 PM

Hello Francis,

My name is Nikolay and I will be covering my colleague Petar until he returns from his absence.

Setting the child id as this.grid.dataItem(e) does not return the correct id as grid.dataItem(e) refers to the master Grid. This could be avoided by creating a new grid instance and checking if a child row has fired it:

 

onChange: function (e) {	
          var grd = e.sender;	
          var isDetailGrid = grd.element[0].id.indexOf("detail") != -1;	
          var detailID;	
          if(isDetailGrid) {	
             detailID = grd.dataItem(grd.select());	
             }	
          	
          var id = this.idSelection;  	
          var idChild = detailID ? detailID.Id : "";  

 

Please find the Dojo demo revised at the following link: http://dojo.telerik.com/AqARekul

Please let me know if you have any questions.

 

Regards,
Nikolay
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 29 Nov 2019, 03:53 PM

Thanks! for the reply it's almost what I want.

The only thing left is that the selection of the two grids are independent. If I select something from group 2, it returns parent 1. I have to select parent 2 to return the correct ID.

0
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 29 Nov 2019, 09:18 PM

Here is my latest version. It's exactly what I want to do :

Dojo

It might be a good thing that Kendo implements the methods to get the data from the child and his parent. In fact, its use is currently very complicated. A very big thank you to you both. You made my day!

0
Nikolay
Telerik team
answered on 03 Dec 2019, 01:48 PM

Hi Francis,

I am very happy to hear what I offered helped you resolve the situation.

Implementing these methods will be definitely discussed with the team and if needed, the necessary changes will be applied.

If there is anything else we could help with, please contact us back.

Regards,
Nikolay
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Petar
Telerik team
FranckSix
Top achievements
Rank 2
Iron
Iron
Veteran
Nikolay
Telerik team
Share this question
or