get editor template grid key when adding new row

3 posts, 0 answers
  1. Adam King
    Adam King avatar
    23 posts
    Member since:
    May 2010

    Posted 21 May 2014 Link to this post

    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. Adam King
    Adam King avatar
    23 posts
    Member since:
    May 2010

    Posted 21 May 2014 Link to this post

    Im posting my search page with both grids so give you an idea of where I am at.
  3. Kendo UI is VS 2017 Ready
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 23 May 2014 Link to this post

    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!
     
Back to Top