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

get editor template grid key when adding new row

2 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam King
Top achievements
Rank 1
Adam King asked on 21 May 2014, 04:47 PM
I have 2 grids on my cshtml. The 'child' is inside a kend-tmpl template.
The nested grid is editable in a popup using an editor template.

Im wondering how do I pass the key of nested grid to the editor template?

The editor template's datasource action is dependent upon the parent key. When editing I can get the key, but only when adding new I am stuck.

Ive looked at 2 ways of doing this. one is with a field default.value on the grid's datasource.Model.Field. Two is on the grid edit event I assign the model's field the value after looking it up.

Option 1: The default value gets passed through but it seems I can only use simple types, hard coded like integers.
model.Field(i => i.PersonID).DefaultValue(222); THIS WORKS
model.Field(i => i.PersonID).DefaultValue("#=PersonKey#"); THIS fails on convert string to int.
model.Field(i => i.PersonID).DefaultValue(new { PersonID = "#=PersonKey#"  }); This fails on conversion from anon type


model.Field(i => i.PersonID).DefaultValue("#=PersonKey#");


Option 2: The grid edit javascript function hits and I want to execute this code before the editor template's data.read action is called.
function onEditRequest(e) {   
    var PersonID = $("#PersonID").val();
    //check if record is new
    if (e.model.isNew()) {
        //set the default value for StateID
        e.model.set("PersonID", PersonID);
    }
}
The problem is that this function above is not called before the editor template's function (dropdown list datasource .read action)
In fact when debugging in each function it will go back and forth (almost line by line) so there is no guarantee the edit is called before the datasource read (which requires the key)

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Adam King
Top achievements
Rank 1
answered on 21 May 2014, 11:35 PM
Im posting my search page with both grids so give you an idea of where I am at.
0
Petur Subev
Telerik team
answered on 23 May 2014, 10:27 AM
Hello Adam,

I posted a reply in the support thread that you opened on the same subject. Feel free to continue our conversation in just one of the two threads.

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Adam King
Top achievements
Rank 1
Answers by
Adam King
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or