Thanks
11 Answers, 1 is accepted
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
Thanks
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
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;
}
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
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;
Boyan Dimitrov
Telerik
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
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
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.
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