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

When I filter out data on tree list I am running into 2 issues:

 1) the number of pages doesn't reflect the number of items shown in the list

 2) the child items will remain in the list even if filtered out

My expectation is that when filter is applied, it would only show Carla and have 1 page on paging bar.  Strangely if I execute $("#AttendeeGrid").data("kendoTreeList").dataSource.read(); again after filtering through browser console the children are then removed.

View

<script type="text/javascript">
    var filter = false;
 
    function toggleFilter() {
        filter = !filter;
        $("#AttendeeGrid").data("kendoTreeList").dataSource.read();
        $("#AttendeeGrid").data("kendoTreeList").dataSource.page(1);
    }
 
    function attendeeParams() {
        return {
            myFilter: filter
        }
    }
</script>
@(Html.Kendo().TreeList<AttendeeItem>()
            .Name("AttendeeGrid")
            .Columns(columns =>
            {
                columns.Add().Field(x => x.firstName).Title("First");
            })
        .Sortable()
        .DataSource(dataSource => dataSource
        .ServerOperation(false)
        .Read(read => read.Action("attendee_Read", "Home").Data("attendeeParams"))
        .Model(m => {
            m.Id(x => x.primaryRegistrationId);
            m.ParentId(x => x.parentRegistrationId);
            m.Expanded(true);
        })
        )
        .Pageable(p => p.PageSize(5))
        .Scrollable(false)
      )
<button onclick="toggleFilter()">Toggle filter</button>

 

Controller

...
public IActionResult attendee_Read([DataSourceRequest] DataSourceRequest request, GetAttendeesParams getAttendeesParams)
        {
            AttendeeItem[] items;
            if (getAttendeesParams.myFilter)
            {
                items = new[]
                {
                    new AttendeeItem
                    {
                        primaryRegistrationId = 1,
                        firstName = "Carla",
                        parentRegistrationId = null
                    }
                };
            }
            else
            {
                items = new[]
                {
                    new AttendeeItem
                    {
                        primaryRegistrationId = 1,
                        firstName = "Carla",
                        parentRegistrationId = null
                    },
                    new AttendeeItem
                    {
                        primaryRegistrationId = 2,
                        firstName = "Roger",
                        parentRegistrationId = null
                    },
                    new AttendeeItem
                    {
                        primaryRegistrationId = 3,
                        firstName = "Katy",
                        parentRegistrationId = null
                    },
                    new AttendeeItem
                    {
                        primaryRegistrationId = 4,
                        firstName = "Bob",
                        parentRegistrationId = null
                    },
                    new AttendeeItem
                    {
                        primaryRegistrationId = 5,
                        firstName = "Avni",
                        parentRegistrationId = 1
                    },
                    new AttendeeItem
                    {
                        primaryRegistrationId = 6,
                        firstName = "George",
                        parentRegistrationId = null
                    },
                };
                 
            }
 
            return Json(items.ToTreeDataSourceResult(request));
        }
    }
 
    public class AttendeeItem
    {
        public string firstName { get; set; }
        public int primaryRegistrationId { get; set; }
        public int? parentRegistrationId { get; set; }
    }
 
    public class GetAttendeesParams
    {
        public bool myFilter { get; set; }
    }
Tsvetomir
Telerik team
 answered on 22 Oct 2019
1 answer
124 views

Hi All

 

I'm using the panelbar in an asp.net core project, like so:

 

        @(Html.Kendo().PanelBar().Name("s").Items(p =>
        {

p.Add().Text("Manufacturers").Content(@<text>

 

However, I have noticed that nothing appears on the page in the browser. Please advise?

 

 

Aleksandar
Telerik team
 answered on 21 Oct 2019
1 answer
216 views

Hello Folks,

I always get the "there was an error running the selected code generator: "Package restore failed. Rolling back package changes for 'projectname'"-Error when i try to add new Razor Pages. What's the Problem? I'm using VS2019 and the ASP.NET Telerik Trial

Aleksandar
Telerik team
 answered on 21 Oct 2019
3 answers
762 views

I made two identical grids.
One using the Html helper and one using the Tag helper.
Both have inline editing enabled.

However the editor templates don't seem to correspond or not even be present in some cases.
I've attached a screenshot.

How do I just make it work in both cases?

Pavlos
Top achievements
Rank 1
 answered on 18 Oct 2019
1 answer
2.0K+ views

I am trying to achieve inline insertion in a grid with client side code. I am using tag helper and generating toolbar with custom button and binding click event with javaScript function. And through this function I need to achieve functionality of "Create" button under grid's toolbar option. 

To elaborate the things, there are two toolbar one is "kindo-toolbar" and another is "toolbar" under "kendo-grid". Toolbar under kendo-grid is having "Add new record" button and on click on this button generates new blank row in grid to add new record. This same functionality I need to achieve through "Kendo-toolbar" item button, where I can bind a click event with a javascript function. So is there a way to implement inline row adding with toolbar item with javascript or any other approach?

<div class="demo-section k-content wide">
        <kendo-toolbar name="ToolBar">
            <toolbar-items>
                <item type="CommandType.Button" icon="add" text="" click="buttonClick" />               
            </toolbar-items>
        </kendo-toolbar>
    </div>
 
<kendo-grid name="grid" height="550">
    <datasource page-size="20" type="DataSourceTagHelperType.Custom" custom-type="odata" batch="true">
        <transport>
        </transport>
        <schema>
            <model id="ProductID">
                <fields>
                    <field name="ProductName"></field>
                    <field name="UnitPrice" type="number"></field>
                    <field name="UnitsInStock" type="number"></field>
                </fields>
            </model>
        </schema>
    </datasource>
    <editable mode="incell" />
    <pageable button-count="5" refresh="true" page-sizes="new int[] { 5, 10, 20 }">
    </pageable>
     
    <toolbar>
        <toolbar-button name="create" text="Add new record"></toolbar-button>
        <toolbar-button name="save" text="Save Changes"></toolbar-button>
        <toolbar-button name="cancel" text="Cancel Changes"></toolbar-button>
         
    </toolbar>
     
    <columns>
        <column field="ProductName" title="Product Name" width="240" />
        <column field="UnitPrice" title="Unit Price" />
        <column field="UnitsInStock" title="Units In Stock" />
        <column field="Discontinued" title="Discontinued" width="150" />
        <column>
            <commands>
                <column-command text="Delete" name="destroy"></column-command>
            </commands>
        </column>
    </columns>
</kendo-grid>
 
<script>
    function buttonClick(e) {       
        alert("Button Clicked");
    }
</script>

 

Eyup
Telerik team
 answered on 18 Oct 2019
3 answers
1.7K+ views

I am having dockerized Asp.Net Core application and using telerik UI for Asp.Net Core licensed NuGet Package by creating Telerik Package Source with physical path on my disk for nupkg file. All development was going well in debug mode, but when I tried to make a release, its giving the error - Unable to find package Telerik.UI.for.AspNet.Core with version >= 2018.2.620. Then it says that Found 1 version in nuget.org with Version 2016.3.914. 

I don't think I should use this older version from nuget.org and moreover I will get trial version there.

Please suggest, if I am missing some steps to reference it properly.

Ianko
Telerik team
 answered on 17 Oct 2019
3 answers
2.7K+ views

Hi,

I'm using Kendo professional for Asp.net Core.

I got the error in "Session.GetObjectFromJson<IList< " and "Session.SetObjectAsJson( "

SeverityCodeDescriptionProjectFileLineSuppression State
ErrorCS1061'ISession' does not contain a definition for 'GetObjectFromJson' and no accessible extension method 'GetObjectFromJson' accepting a first argument of type 'ISession' could be found (are you missing a using directive or an assembly reference?)

I tried to fix by install Session from Nuget. but I can't find any package called Session in Nuget.  Thank you if you can help.

 

ProductService.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using Kendo.Mvc.Examples.Extensions;

namespace Kendo.Mvc.Examples.Models
{
public class ProductService : BaseService, IProductService
    {
        private static bool UpdateDatabase = false;
        private ISession _session;

        public ISession Session { get { return _session; } }

        public ProductService(IHttpContextAccessor httpContextAccessor)
        {
            _session = httpContextAccessor.HttpContext.Session;
        }

        public IEnumerable<ProductViewModel> Read()
        {
            return GetAll();
        }

        public IList<ProductViewModel> GetAll()
        {
            using (var db = GetContext())
            {
                var result = Session.GetObjectFromJson<IList<ProductViewModel>>("Products");

                if (result == null || UpdateDatabase)
                {
                    var categories = db.Categories.ToList();

                    result = db.Products.ToList().Select(product =>
                    {
                        var category = categories.First(c => product.CategoryID == c.CategoryID);

                        return new ProductViewModel
                        {
                            ProductID = product.ProductID,
                            ProductName = product.ProductName,
                            UnitPrice = product.UnitPrice.HasValue ? product.UnitPrice.Value : default(decimal),
                            UnitsInStock = product.UnitsInStock.HasValue ? product.UnitsInStock.Value : default(int),
                            QuantityPerUnit = product.QuantityPerUnit,
                            Discontinued = product.Discontinued,
                            UnitsOnOrder = product.UnitsOnOrder.HasValue ? product.UnitsOnOrder.Value : default(int),
                            CategoryID = product.CategoryID,
                            Category = new CategoryViewModel()
                            {
                                CategoryID = category.CategoryID,
                                CategoryName = category.CategoryName
                            },
                            LastSupply = DateTime.Today
                        };
                    }).ToList();

                    Session.SetObjectAsJson("Products", result);
                }

                return result;
            } 
        }

        public void Create(ProductViewModel product)
        {
            if (!UpdateDatabase)
            {
                var products = GetAll();
                var first = products.OrderByDescending(e => e.ProductID).FirstOrDefault();
                var id = (first != null) ? first.ProductID : 0;

                product.ProductID = id + 1;

                products.Insert(0, product);

                Session.SetObjectAsJson("Products", products);
            }
            else
            {
                using (var db = GetContext())
                {
                    var entity = new Product();

                    entity.ProductName = product.ProductName;
                    entity.UnitPrice = product.UnitPrice;
                    entity.UnitsInStock = (short)product.UnitsInStock;
                    entity.Discontinued = product.Discontinued;
                    entity.CategoryID = product.CategoryID;

                    if (entity.CategoryID == null)
                    {
                        entity.CategoryID = 1;
                    }

                    if (product.Category != null)
                    {
                        entity.CategoryID = product.Category.CategoryID;
                    }

                    db.Products.Add(entity);
                    db.SaveChanges();

                    product.ProductID = (int)entity.ProductID;
                }
            }
        }

        public void Update(ProductViewModel product)
        {
            if (!UpdateDatabase)
            {
                var products = GetAll();
                var target = products.FirstOrDefault(e => e.ProductID == product.ProductID);

                if (target != null)
                {
                    target.ProductName = product.ProductName;
                    target.UnitPrice = product.UnitPrice;
                    target.UnitsInStock = product.UnitsInStock;
                    target.Discontinued = product.Discontinued;
                    target.CategoryID = product.CategoryID;
                    target.Category = product.Category;
                }

                Session.SetObjectAsJson("Products", products);
            }
            else
            {
                using (var db = GetContext())
                {
                    var entity = new Product();

                    entity.ProductID = product.ProductID;
                    entity.ProductName = product.ProductName;
                    entity.UnitPrice = product.UnitPrice;
                    entity.UnitsInStock = (short)product.UnitsInStock;
                    entity.Discontinued = product.Discontinued;
                    entity.CategoryID = product.CategoryID;

                    if (product.Category != null)
                    {
                        entity.CategoryID = product.Category.CategoryID;
                    }

                    db.Products.Attach(entity);
                    db.Entry(entity).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }

        public void Destroy(ProductViewModel product)
        {
            if (!UpdateDatabase)
            {
                var products = GetAll();
                var target = products.FirstOrDefault(e => e.ProductID == product.ProductID);

                if (target != null)
                {
                    products.Remove(target);
                }

                Session.SetObjectAsJson("Products", products);
            }
            else
            {
                using (var db = GetContext())
                {
                    var entity = new Product();

                    entity.ProductID = product.ProductID;

                    db.Products.Attach(entity);

                    db.Products.Remove(entity);

                    var orderDetails = db.OrderDetails.Where(pd => pd.ProductID == entity.ProductID);

                    foreach (var orderDetail in orderDetails)
                    {
                        db.OrderDetails.Remove(orderDetail);
                    }

                    db.SaveChanges();
                }
            }
        }
    }
}

Viktor Tachev
Telerik team
 answered on 16 Oct 2019
12 answers
2.5K+ views

Hello,

How to reload a timeline (with Kendo grid I can use grid.dataSource.read();)

robert

Robert Madrian
Top achievements
Rank 1
Veteran
Iron
 answered on 16 Oct 2019
5 answers
1.2K+ views

Hi,

We've just bought the UI for ASP.NET Core components and have started using the Grid component in our ASP.NET Core 2.1 project. From what I understand, unlike the ASP.NET MVC grid, the ASP.NET Core grid is not a true server-side component and the Html and TagHelpers are basically just wrappers for the Kendo UI for jQuery client-side javascript based component, right?

If that's the case then what is the best way to implement server-side formatting/rendering of certain data in the columns of the grid? Until now we've used normal html tables and put our custom TagHelpers and text formatting functions calls directly in the cells of those tables (in the .cshtml files). For example we have a custom class that wraps an integer and converts that value to minutes and various other things.

I've noticed there is the ClientTemplate of the columns in the grid but you can't put TagHelpers or .ToString() methods in those templates since they are just evaluated in javascript on the client.

Is there a way to use the MVC grid in Core projects?

/Marcus

 

Angel Petrov
Telerik team
 answered on 15 Oct 2019
3 answers
394 views

Hallo zusammen,

ich habe in meinem Grid zwei Knöpfe, die das edit event auslösen. Ich rufe damit das gleiche Popup auf, aber abhängig davon welcher Edit button geklickt wurde, müssen im Popup verschiedene Elemente ein- oder ausgeblendet werden. Ich habe noch keine Möglichkeit gefunden wie ich herausbekomme welcher Knopf geklickt wurde.

Beide Button befinden sich in der Toolbar
        .ToolBar(t =>
        {
            t.Create().Text("Add User");
            t.Create().Text("Add Host");
        }
 und das Event folgendermaße deklariert:
        .Events(events => events
            .Edit("insertPopupCaption")
        )

Kann mir hier bitte jemand weiterhelfen?

Kind regards
Markus

Markus
Top achievements
Rank 1
 answered on 15 Oct 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?