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

Want to select first item after cancelling create

1 Answer 116 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Franz
Top achievements
Rank 1
Franz asked on 14 Jan 2015, 10:55 AM
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());
      
   }

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 16 Jan 2015, 07:45 AM

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.

 
Tags
ListView
Asked by
Franz
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or