Telerik Forums
UI for ASP.NET Core Forum
5 answers
159 views

I am using the TreeList as defined below.  I can successfully get and display my hierarchy.  However, when I go to update,  the [Group group] is empty like it newed up an instance of the object instead of took it from the tree.  What am I missing?

TreeList Definition:

<script id="photo-template" type="text/x-kendo-template">
    <div class='group-photo'
         style='background-image: url(@Url.Content("~/images/32/building.png"));'></div>
    <div class='group-name'>#: Name #</div>
</script>
 
<div class="demo-section k-content">
    <h4>Customer Groups</h4>
    @(Html.Kendo().TreeList<GsiPortal.Models.Group>()
          .Name("treelist")
          .Columns(columns =>
          {
              columns.Add().Field(e => e.Name).Width(220).TemplateId("photo-template");
              columns.Add().Field(e => e.DisplayName);
              columns.Add().Field(e => e.Description);
              columns.Add().Field(e => e.AddTimestamp).Width(220).Title("Timestamp").Format("{0:MMMM d, yyyy}");
              columns.Add().Command(c =>
              {
                  c.CreateChild().Text("Add child");
                  c.Edit();
                  c.Destroy();
              })
                  .HtmlAttributes(new
                  {
                      style = "text-align: center;"
                  });
          })
          .Editable(e => e.Mode(TreeListEditMode.InLine))
          .Pageable()
          .Selectable(selectable => selectable.Mode(TreeListSelectionMode.Single))
          .Navigatable()
          .Sortable()
          .Scrollable(true)
          .Filterable()
          .HtmlAttributes(new { style = "height:550px;" })
          .DataSource(dataSource => dataSource
              .PageSize(20)
              .Model(m =>
              {
                  m.Id(f => f.Id);
                  m.ParentId(f => f.ParentId);
                  m.Expanded(true);
                  m.Field(f => f.Name);
                  m.Field(f => f.DisplayName);
                  m.Field(f => f.Description);
                  m.Field(f => f.AddTimestamp).Editable(false);
                  m.Field(f => f.LastActionTimestamp).Editable(false);
              })
              .Create(create => create.Action("CreateJson", "Groups"))
              .Read(read => read.Action("AllJson", "Groups"))
              .Update(update => update.Action("UpdateJson", "Groups"))
              .Destroy(delete => delete.Action("DestroyJson", "Groups"))
          ))
 
    <style>
        .group-photo {
            display: inline-block;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-size: 40px 44px;
            background-position: center center;
            vertical-align: middle;
            line-height: 41px;
            box-shadow: inset 0 0 1px #999, inset 0 0 10px rgba(0,0,0,.2);
        }
 
        .group-name {
            display: inline-block;
            vertical-align: middle;
            line-height: 41px;
            padding-left: 10px;
        }
    </style>

 

Control Methods

public async Task<JsonResult> AllJson([DataSourceRequest] DataSourceRequest request)
{
    var all = await groupService.GetAllAsync();
    var result = await all.ToTreeDataSourceResultAsync(request,
        e => e.Id,
        e => e.ParentId,
        e => e);
 
    return Json(result);
}
 
public async Task<JsonResult> CreateJson([DataSourceRequest] DataSourceRequest request, Group group)
{
    if (ModelState.IsValid)
    {
        customerDbContext.Add(group);
        await customerDbContext.SaveChangesAsync();
    }
 
    return Json(new[] { group }.ToTreeDataSourceResult(request, ModelState));
}
 
public async Task<JsonResult> UpdateJson(
    [DataSourceRequest] DataSourceRequest request,
    Group group)
{
    if (ModelState.IsValid)
    {
        customerDbContext.Update(group);
        await customerDbContext.SaveChangesAsync();
    }
 
    return Json(new[] { group }.ToTreeDataSourceResult(request, ModelState));
}
 
public async Task<JsonResult> DestroyJson([DataSourceRequest] DataSourceRequest request, Group group)
{
    if (ModelState.IsValid)
    {
        customerDbContext.Group.Remove(group);
        await customerDbContext.SaveChangesAsync();
    }
 
    return Json(new[] { group }.ToTreeDataSourceResult(request, ModelState));
}

Also, I have attached a picture of the TreeLIst

Viktor Tachev
Telerik team
 answered on 21 Dec 2018
5 answers
1.6K+ views

I have an asp.net form with various textboxes and datepickers.   I allow the user to fill in the form and if they decide to start again I have a reset button for them.

The reset button should reset the form to its original model data.  To be clear I don't want to reset the form to blank values, I want to reset all the inputs to their original modal values.

This works nicely for the textboxes however after hitting reset button the datepicker simply displays a "d" and not the original model value.

I use the following javascript/jquery to reset the form:

$(this).closest('form')[0].reset();

 

Here is my extract form code with the datepicker:

<tr>
    <td><label asp-for="Aircraft.SerialNumber" class="frm-label"></label></td>
    <td>
        <input asp-for="Aircraft.SerialNumber" autocomplete="off" class="k-textbox k-state-disabled" style="width:400px" disabled />
        <span asp-validation-for="Aircraft.SerialNumber" class="text-danger"></span>
    </td>
</tr>
    <tr>
    <td><label asp-for="Aircraft.ManufactureDate" class="frm-label"></label></td>
    <td>
        <kendo-datepicker name="DatePicker" for="Aircraft.ManufactureDate" class=""  style='width: 400px;' />
        <span asp-validation-for="Aircraft.ManufactureDate" class="text-danger"></span>
    </td>
</tr>

 

Konstantin Dikov
Telerik team
 answered on 19 Dec 2018
1 answer
301 views

Hi,

I use Telerik UI for ASP.NET Core Upload to upload an image to Azure storage, and it works.

I tried to use RedirectToAction to show the uploaded image in Details action, and the page keep stayed and didn't redirect. The codes are in PaperCognitionController, Index page for upload, and Details page to show image. 

 

I tried another action CharacterCognitionController Index to use RedirectToAction to test the redirect function, it worked but only the PaperCognitionController.SaveAsync didn't. 

 

Is there any problem with using Upload control?

And how to upload my code? The attachments cannot be zip file?

Marin Bratanov
Telerik team
 answered on 19 Dec 2018
2 answers
2.3K+ views

I have managed to get my Kendo Dialog working properly with the grid however I cannot figure out the proper JQuery code to have it delete the record on confirmation.

 

Here is the my grid and dialog:

@(Html.Kendo().Grid<OrderStatusModel>()
              .Name("grd_OrderStatus")
              .Columns(columns =>
              {
                  columns.Command(command =>
                  {
                      command.Edit()
                          .Text(" ")
                          .HtmlAttributes(new {style = "width:40%"});
                      command.Custom("Destroy")
                          .IconClass("k-icon k-i-close")
                          .Click("showDeleteConfirmation")
                          .Text(" ")
                          .HtmlAttributes(new {style = "width:40%"});
                  }).Width("15%");
                  columns.Bound(p => p.OrderStatusId).Hidden(controller.IsLoggedInUserRootAdmin != true).Width("15%").Title("ID");
                  columns.Bound(p => p.Description).Width("70%");
              })
              .ToolBar(toolbar => toolbar.ClientTemplateId("GridToolbarTemplate"))
              .Editable(editable => editable.DisplayDeleteConfirmation(false)
                  .Mode(GridEditMode.PopUp))
              .HtmlAttributes(new {style = "height: 100%;"})
              .Scrollable()
              .Sortable()
              .Pageable(pageable => pageable
                  .Refresh(true)
                  .PageSizes(true)
                  .ButtonCount(5))
              .AutoBind(controller.IsLoggedInUserRootAdmin != true)
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Read(read => read.Action("OrderStatus_Read", "OrderStatus", new {area = "OrderPad"}).Data("GetSelectedClientID"))
                  .Create(update => update.Action("OrderStatus_Create", "OrderStatus", new {area = "OrderPad"}).Data("GetSelectedClientID"))
                  .Update(update => update.Action("OrderStatus_Update", "OrderStatus", new {area = "OrderPad"}).Data("GetSelectedClientID"))
                  .Destroy(update => update.Action("OrderStatus_Destroy", "OrderStatus", new {area = "OrderPad"}))
                  .Events(events => events.Error("error_handler"))
                  .Model(model => model.Id(p => p.OrderStatusId))
 
              ))
 
@(Html.Kendo()
      .Dialog()
      .Name("dlg_DeleteConfirmation")
      .Modal(true)
      .Title("Confirm Delete")
      .Content("Are you sure you want to delete this Order Status?")
      .Visible(false)
      .Actions(a =>
      {
          a.Add().Text("No").Action("cancelDelete");
          a.Add().Text("Yes").Action("confirmDelete").Primary(true);
      })
      )

 

And here is my confirmDelete script, this is one of a dozen different pieces of code I have found scattered across the internet related to this topic however none of them work.

 

function confirmDelete(e) {
    var grid = $("#grd_OrderStatus").data("kendoGrid");
    var tr = $(e.currentTarget).closest("tr");
    var data = grid.dataItem(tr);
    grid.dataSource.remove(data);  //prepare a "destroy" request
    grid.dataSource.sync();
    $('#dlg_DeleteConfirmation').data("kendoDialog").close();
}

 

Any suggestions on how to get this to work?

 

Thanks

M

 

Georgi
Telerik team
 answered on 19 Dec 2018
1 answer
112 views

Hello,

Is there a way to change the width of the tab titles so that longer title names can be use without truncation or word wrapping to the next line.  I could not find anything in the API docs or demos.

Please refer to the attached image.

Thanks,

Doug

Marin Bratanov
Telerik team
 answered on 19 Dec 2018
4 answers
1.2K+ views

Using this Grid with the Groups command button definition, I want to navigate to another MVC Action passing a CustomerId value as a parameter.  I have an Event handler (with no JavaScript) but am not sure if this is the right approach.  Should this be some type of HTML call?  If JavaScript is the right way to do this then please supply some code.

This is for ASP.NET Core.  Thanks in advance for your help, Joel.

@(Html.Kendo().Grid<GsiPortal.Models.Customer>()
                      .Name("grid")
                      .Columns(columns =>
                      {
                          columns.Bound(p => p.Name);
                          columns.Bound(p => p.DisplayName).Title("Display Name");
                          columns.Bound(p => p.AddTimestamp).Format("{0:MM/dd/yyyy}");
                          columns.Command(command => command.Custom("Groups").Click("goGroups"));
                          columns.Command(command => command.Edit()).MinResizableWidth(75);
                          columns.Command(command => command.Destroy()).MinResizableWidth(75);
                      })
                      .Editable(editable => editable.Mode(GridEditMode.InLine)) //.TemplateName("CustomerEdit")) //Turn on the inline cell editing by setting
                      .Pageable()
                      .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
                      .PersistSelection(true)
                      .Navigatable()
                      .Sortable()
                      .Scrollable()
                      .Filterable()
                      .HtmlAttributes(new { style = "height:550px;" })
                      .DataSource(dataSource => dataSource
                          .Ajax()
                          .PageSize(20)
                          .ServerOperation(false)
                          .Events(events => events.Error("error_handler"))
                          .Model(model =>
                          {
                              model.Id(p => p.Id);
                              model.Field(p => p.Id).Editable(false);
                              model.Field(p => p.AddTimestamp).Editable(false);
                          })
                          .Read("IndexJson", "Customers")
                          .Update("Edit", "Customers")
                          .Create("CreateJson", "Customers")
                          .Destroy("DeleteJson", "Customers")
              ))

 

Joel
Top achievements
Rank 3
Bronze
Iron
Iron
 answered on 18 Dec 2018
1 answer
992 views

How do I pass field data from the master grid to the detail grid in the modal popup editor in kendo ui mvc? And how do I do the opposite?

 

Thanks,

James

Alex Hajigeorgieva
Telerik team
 answered on 18 Dec 2018
4 answers
370 views

I need a TreeView example for ASP.NET Core 2.2 that uses Binding and shows me how I can capture the drag/drop events from the control with some context information.  Your example shows that it can be done but I see no way to capture the data item that is bound to the node or even wire up a KeyValue to a node so when it is clicked that I have a breadcrumb back to my data store. 

I appreciate your help,

Joel

My current TreeView:

    Html.Kendo().TreeView()
        .TemplateId("treeview-template")
        .DragAndDrop(true)
        .Name("kendoTreeView")
        .Events(events => events
            .Change("onChange")
            .Select("onSelect")
            .Drop("onDrop")
            .DragEnd("onDragEnd")
        )
        .BindTo(Model, (NavigationBindingFactory<TreeViewItem> mappings) =>
        {
            mappings.For<Group>(binding => binding.ItemDataBound((item, group) =>
            {
                item.Text = group.Name;
                item.Id = $"{group.Id}";
                item.ImageUrl = group.ImageUrl;
                item.Expanded = true;
            })
                .Children(group => group.Children));
        })
          )
 
<script>
    var treeview;
 
    function onSelect(e) {
        alert(e.node);
    }
 
    function onChange(e) {
        alert(e.node);
    }
 
    function onDrop(e) {
        alert(e.node);
    }
 
    function onDragEnd(e) {
        alert(e.node);
    }
 
    $(document).ready(function() {
        treeview = $("#treeview").data("kendoTreeView");
    });
</script>

 

Ivan Danchev
Telerik team
 answered on 18 Dec 2018
2 answers
602 views

I have a multiselect setup as an Editor Template utilized by the grids popup editor, the control loads properly, displays the data, allows me to select multiple Order Types, but then returns null to my model every time when I save the changes on the popup editor. 

 

How do I wire up the value of the MultiSelect to my model when it is an Editor Template for a Grid Popup?

 

Here is my Editor Template code:

@model IEnumerable<int>
@(Html.Kendo().MultiSelect()
      .Name("OrderTypeIDs")
      .DataTextField("Description")
      .DataValueField("OrderTypeID")
      .DataSource(d => d
          .Ajax()
          .Read(r => r
              .Action("OrderTypes_Read", "Locations")
              .Data("GetSelectedClientID")))
      .TagMode(MultiSelectTagMode.Multiple)
      .Value(Model)
      )

 

Here is the underlying model class:

public class LocationsModel : INotifyPropertyChanged
{
    public LocationsModel() : base()
    {
    }
 
    [ScaffoldColumn(false)]
    public decimal LocationId { get; set; }
 
    [ScaffoldColumn(false)]
    public string ClientID { get; set; }
 
    [DisplayName("Code")]
    [Required]
    public string LocationCode { get; set; }
 
    [Required]
    public string Name { get; set; }
 
    [DisplayName("Address 1")]
    [Required]
    public string Address1 { get; set; }
 
    private string address2;
    [DisplayName("Address 2")]
    public string Address2
    {
        get => address2 ?? "";
        set => address2 = value ?? "";
    }
 
    [Required]
    public string City { get; set; }
 
    [Required]
    public string State { get; set; }
 
    [Required]
    public string Country { get; set; }
 
    [DisplayName("Zip Code")]
    [Required]
    public string ZipCode { get; set; }
 
    [DisplayName("Phone")]
    [Required]
    public string PhoneNumber { get; set; }
 
    [UIHint("OrderTypeIDs")]
    [DisplayName("Allowed Order Types")]
    public IEnumerable<int> OrderTypeIDs { get; set; }
    [DisplayName("# of O Types")]
    [ReadOnly(true)]
    public int OrderTypeCount => OrderTypeIDs?.Count() ?? 0;
 
    [ScaffoldColumn(false)]
    public string CreatedBy { get; set; }
    [ScaffoldColumn(false)]
    public DateTime CreatedOn { get; set; }
    [ScaffoldColumn(false)]
    public string LastUpdatedBy { get; set; }
    [ScaffoldColumn(false)]
    public DateTime LastUpdatedOn { get; set; }
 
 
    public event PropertyChangedEventHandler PropertyChanged;
 
}
Ivan Danchev
Telerik team
 answered on 18 Dec 2018
3 answers
93 views

Does anyone have an example of an EditorTemplate for a Grid that handles a BitMask field?

 

Thanks

M

Tsvetomir
Telerik team
 answered on 18 Dec 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?