This is a migrated thread and some comments may be shown as answers.
How can I find out which particular columns cell was clicked for editing
11 Answers 517 Views
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 15 Jul 2013, 11:26 PM
can you please suggest as to how can i access the column name of the cell being current edited. I am using edit event of the grid and would like to apply different validation checks depending on the type of column that is being edited.

Thanks

11 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 16 Jul 2013, 08:49 AM
Hello Rick,

You can get the current row being edited, by using the "edit" event argument and its container property like this:

var grid = $("#grid").data("kendoGrid");
            grid.bind("edit",function(e){
                console.log(e.container);
            });
        });


However there is no built-in functionality to get the name of the column that is currently edited. You can check for the focused input and get its name attribute that is equal to the field name, as a possible solution.

As you are talking about a custom validation of the grid's cells, I would suggest you to use the built-in validator. Using it you can perform custom validation for each of the columns, based on their type or other properties. Please check this forum topic to see a discussion about a possible implementation:

http://www.kendoui.com/forums/kendo-ui-framework/validation/unable-to-get-custom-validation-working-on-a-grid.aspx


Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rick
Top achievements
Rank 1
answered on 16 Jul 2013, 07:11 PM
Thanks Kiril, I was able to grab the name as suggested by you. Now the bigger /broader issue is that I want to validate values of  a particular cell ( the one being edited) against another cell and want this validation to trigger as soon as the editing on the current cell is completed, in other words as soon as the editable cell loses focus. Now the question is there an event like aftercellupdate / aftercelledited ( or before cell update).

Thanks
0
Kiril Nikolov
Telerik team
answered on 17 Jul 2013, 09:50 AM
Hello Rick,

You can use the jQuery .blur() event handler to execute the validation when the element being edited loses focus. You can bind to the edit event of the grid, find all the inputs and attach the handler.

For your convenience here is a jsBin example which demonstrates a possible implementation.
 
Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
evb
Top achievements
Rank 1
answered on 24 Jan 2014, 12:27 PM
Hi Kiril,

You writed:
"However there is no built-in functionality to get the name of the column that is currently edited. You can check for the focused input and get its name attribute that is equal to the field name, as a possible solution."

Your collague Alexander has a solution for this, see his post: http://www.kendoui.com/forums/permalink/cltSVQhahkqVx2ehrNdGfA
edit: function(e){
      var grid = this;
      var fieldName = grid.columns[e.container.index()].field;
}
Regards,


0
Kiril Nikolov
Telerik team
answered on 27 Jan 2014, 10:11 AM
Hello Eric,

I have suggested a way to achieve this functionality. It is not built-in but it gets the job done, the solution provided by my colleague does not depend on built-in method or property that gives information about the currently edited column, but it also gets the job done. There are a few way to achieve certain functionality, based on your project and current approach.

I am really glad to hear that you liked the solution that was provided to you.

Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sharon
Top achievements
Rank 1
answered on 05 Apr 2016, 05:24 AM
But what about sub columns?
0
Boyan Dimitrov
Telerik team
answered on 06 Apr 2016, 02:15 PM

Hello Sharon,

I assume that the question is related to a hierarchy scenario, where there is a detail/child grid. Since it is completely separate grid widget same approach could be as well. The only difference that the grid instance should point to the child/detail grid instance instead. 

grid.columns[e.container.index()].field;

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Narendra
Top achievements
Rank 1
answered on 10 Aug 2017, 08:32 PM

Hello Dim,

Like Sharon asked in the previous question, What about the sub columns(defined as columns.columns). How to find the field or title name of that column? the suggested method is working for direct columns, but for the sub columns, it is throwing an error.

Thanks,

Narendra

0
Boyan Dimitrov
Telerik team
answered on 14 Aug 2017, 03:08 PM

Hello Narendra,

In general the Kendo UI DataSource is designed to work with flat data, but since the columns field returns an array it is possible to access an object in nested array.

Could you please share a sample dojo example that replicates the problem?

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Narendra
Top achievements
Rank 1
answered on 05 Sep 2017, 02:52 PM

HI Boyan,

Sorry for the late response.

please find the requested dojo

I used the same method suggested in this post to find the column name. But in this dojo I have sub-columns. So, if you try to find the column 3 name in the attached dojo, it is throwing an error(Please check console) because it is treating the sub column 2 as column 3.  

So, please help me out to find the correct column 3 the attached dojo.

0
Preslav
Telerik team
answered on 06 Sep 2017, 08:34 AM
Hello Narendra,

I am pasting the answer from the support ticket on the same topic in case anyone from the community encounters the same problem. 

To get the field of the relevant column, I would suggest getting the name attribute of the input as it matches the field name due to the data binding.

For example, the code could look like:

edit:function(e){
  var field = e.container.find("input")[0].name;
  console.log(field);
}


For a runnable example, check the modified Dojo:
Regards,
Preslav
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Rick
Top achievements
Rank 1
evb
Top achievements
Rank 1
Sharon
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Narendra
Top achievements
Rank 1
Preslav
Telerik team
Share this question
or