Want to select first item after cancelling create

2 posts, 0 answers
  1. Franz
    Franz avatar
    7 posts
    Member since:
    Oct 2013

    Posted 14 Jan 2015 Link to this post

    When creating a new entry in listview and deciding to cancel the creation, the entry is removed from listview, but I have problems to get first item selected after that.
    The cancel event seems to have a timing problem.
    Here is my ListView:
    @(Html.Kendo()
                 .ListView(Model)
                 .Name("lstvPermissionGroup")
                 .TagName("div")
                 .ClientTemplateId("permissionGroupTemplate")
                 .ClientAltTemplateId("permissionGroupTemplate")
                 .Editable()
                 .DataSource(ds => ds 
                     .Model(model =>
                     {
                         model.Id("Id");
                         model.Field(f => f.CompanyId).DefaultValue(@Model.First().CompanyId);
                     }) 
                     
                     .Create(create => create.Action("PermissionGroupCreate", "User"))
                     .Update(update => update.Action("PermissionGroupUpdate", "User"))
                     .Read(read => read.Action("PermissionGroups", "User").Data("additionalData") )
                     .Destroy(destroy => destroy.Action("PermissionGroupDelete", "User"))
                     .Events(e =>
                     {
                         e.RequestEnd("onRequestEnd");
                         e.Error("onError");
                     })
                 )
                 .Selectable()
                 .Events(ev =>
                 {
                     ev.Change("onChange");
                     ev.Cancel("onCancel");
                 })
                 )


    and that is my cancel event:

    function onCancel(e) {
          var listView = $('#lstvPermissionGroup').data('kendoListView');
           listView.select(listView.element.children().first());
          
       }
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 16 Jan 2015 Link to this post

    Hello Franz,

    Your cancel event handler should look like this:

    cancel: function() {
     this.one("dataBound", function() {
      this.select(this.element.children().first());
     });                  
    }

    Cancel event is triggered before the actual cancellation as the event can be prevented. Thus you need some timeout or handle next dataBound event.

    Here is a runnable example - http://dojo.telerik.com/@rusev/OkOWu. All you need is to add new record and then click the cancel button, then first item gets selected.

    Regards,
    Nikolay Rusev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top