Telerik Forums
UI for Blazor Forum
1 answer
355 views

Hi,

Would it be feasible to bring in the Telerik asp.net core package to a blazor project and use that as well?

I know using the controls will obviously be different, but there are more available there so was wondering if I could do that to widen the possibilities?

Is there any documentation on how to best go abut doing this if so?

Dimo
Telerik team
 answered on 07 Jan 2022
0 answers
206 views

Hello, I can retrieve the correct data in the TelerikDropDownList but, when I try to update the column, I get a "Value cannot be null. (Parameter 'key')" error. The update functionality works for the other properties in the ActivityResource model. It gives me the error above when I try to update anything from the child models (Activity and Resource). Thanks for the help in advance!

Models:


  public class ActivityResource
    {
        public int ActivityId { get; set; }

        public int ResourceId { get; set; }

        public double Sequence { get; set; }

        public DateTime ScheduledStart { get; set; }

        public DateTime ScheduledEnd { get; set; }

        public double ScheduledDuration { get; set; }



        public Activity Activity { get; set; }

        public Resource Resource { get; set; }
    }

 public class Activity
    {
        public int Id { get; set; }
        public int Number { get; set; }
        public string Name { get; set; } = "New Activity";
        public string Description { get; set; }

        public ICollection<Resource> Resources { get; set; }

        public List<ActivityResource> ActivityResources { get; set; }

    }

public class Resource
    {
        public int Id { get; set; }
        public string Name { get; set; } = "New Resource";
        public string Description { get; set; }

        public int ResourceTypeId { get; set; }
        public virtual ResourceType ResourceType { get; set; }



        public ICollection<Activity> Activities { get; set; }

        public List<ActivityResource> ActivityResources { get; set; }
    }

Controller:
 public async Task UpdateActivityResourceScheduleAsync(ActivityResource schedule)
        {
            // Getting the Schedule that is in the database.
            var targetedSchedule = _ctx.ActivityResources.FirstOrDefault(r => r.ActivityId == schedule.ActivityId && r.ResourceId == schedule.ResourceId);
            bool resquence = false;

            if (targetedSchedule != null)
            {

                if (targetedSchedule.Sequence != schedule.Sequence)
                {
                    resquence = true;
                }
                // Assigning the properties.
                targetedSchedule.Sequence = schedule.Sequence;
                targetedSchedule.ScheduledStart = schedule.ScheduledStart;
                targetedSchedule.ScheduledEnd = schedule.ScheduledEnd;
                targetedSchedule.ScheduledDuration = schedule.ScheduledDuration;
                targetedSchedule.Activity = schedule.Activity;
                targetedSchedule.Resource = schedule.Resource;
                targetedSchedule.ActivityId = schedule.ActivityId;
                targetedSchedule.ResourceId = schedule.ResourceId;
                targetedSchedule.Activity = _ctx.Activities.FirstOrDefault(aId => aId.Id == schedule.ActivityId);
                targetedSchedule.Resource = _ctx.Resources.FirstOrDefault(rId => rId.Id == schedule.ResourceId);

               

            }

                // Updating the properties.
                _ctx.ActivityResources.Update(targetedSchedule);
                await _ctx.SaveChangesAsync();
}

Razor Page:
<TelerikGrid Data="@SchedulesList" Height="550px" FilterMode="@GridFilterMode.FilterMenu"
                 Sortable="true"
                 Pageable="true"
                 PageSize="20"
                 Resizable="true"
                 Reorderable="true"
                 RowDraggable="true"
                 OnStateInit="@((GridStateEventArgs<VentureBlazor.Models.ActivityResource> args) => OnStateInit(args))"
                 OnRowDrop="@((GridRowDropEventArgs<VentureBlazor.Models.ActivityResource> args) => OnRowDropHandler(args))"
                 EditMode="@GridEditMode.Incell"
                 OnUpdate="@UpdateHandler"
                 OnDelete="@DeleteHandler">
                  <DetailTemplate>
                    @{
                        var schedule = context as VentureBlazor.Models.ActivityResource;
                        <TelerikGrid Data="@schedule.Activity.Resources" Pageable="true" PageSize="5">
                            <GridColumns>
                                <GridColumn Field="Name"></GridColumn> 
                                <GridColumn Field="Description"></GridColumn>
                            </GridColumns>
                        </TelerikGrid>
                       
                    }
                </DetailTemplate> 
                 <GridToolBar>
@*            <GridCommandButton Command="Add" Icon="plus" Primary="true">Add Schedule</GridCommandButton>
*@        </GridToolBar>
        <GridColumns>
@*            <GridColumn Field="@(nameof(VentureBlazor.Models.ActivityResourceSchedule.Id))" Editable="false" />
*@            <GridColumn Title="Activity Id" Field="Activity.Id" Editable="false"/>
            <GridColumn Title="Resource Id" Field="Resource.Id" Editable="false"/>
            <GridColumn Field="@(nameof(VentureBlazor.Models.ActivityResource.Sequence))" />           
            <GridColumn Field="@(nameof(VentureBlazor.Models.ActivityResource.ScheduledStart))" />
            <GridColumn Field="@(nameof(VentureBlazor.Models.ActivityResource.ScheduledEnd))" />
            <GridColumn Field="@(nameof(VentureBlazor.Models.ActivityResource.ScheduledDuration))" />           
            <GridColumn Title="Activity Name" Field="@(nameof(VentureBlazor.Models.ActivityResource.ActivityId))">
                <EditorTemplate>
                    @{
                        CurrentlyEditedSchedule = context as VentureBlazor.Models.ActivityResource;
                        <TelerikDropDownList Data="@ActivitiesList"
                        @bind-Value="@CurrentlyEditedSchedule.ActivityId" 
                        TextField="@nameof(Activity.Name)"
                        ValueField="@nameof(Activity.Id)"
                        >
                        
                        </TelerikDropDownList>
                    }
                </EditorTemplate>
                <Template>
                    @{
                    int aId = (context as VentureBlazor.Models.ActivityResource).ActivityId;
                    Activity matchingPos = ActivitiesList.FirstOrDefault(a => a.Id == aId);
                    string textToRender = matchingPos != null ? matchingPos.Name : "Unknown";
                    <text>@textToRender</text>
                }
                </Template>
            </GridColumn>
            <GridColumn Title="Resource Name" Field="@(nameof(VentureBlazor.Models.ActivityResource.ResourceId))">
                <EditorTemplate>
                    @{
                        CurrentlyEditedSchedule = context as VentureBlazor.Models.ActivityResource;
                        <TelerikDropDownList Data="@ResourcesList"
                        @bind-Value="@CurrentlyEditedSchedule.ResourceId" 
                        TextField="@nameof(VentureBlazor.Models.Resource.Name)"
                        ValueField="@nameof(VentureBlazor.Models.Resource.Id)"
                        >
                        
                        </TelerikDropDownList>
                    }
                </EditorTemplate>
                <Template>
                    @{
                    int rId = (context as VentureBlazor.Models.ActivityResource).ResourceId;
                    VentureBlazor.Models.Resource matchingPos = ResourcesList.FirstOrDefault(r => r.Id == rId);
                    string textToRender = matchingPos != null ? matchingPos.Name : "Unknown";
                    <text>@textToRender</text>
                }
                </Template>
            </GridColumn>
            <GridCommandColumn Width="200px" Resizable="false">
                <GridCommandButton Command="Save" Icon="save" ShowInEdit="true">Update</GridCommandButton>
                <GridCommandButton Command="Edit" Icon="edit" Primary="true">Edit</GridCommandButton>
                <GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
                <GridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</GridCommandButton>
            </GridCommandColumn>
        </GridColumns>   
    </TelerikGrid>

@code {

    private List<VentureBlazor.Models.ActivityResource> SchedulesList { get; set; }
    private List<VentureBlazor.Models.Activity> ActivitiesList  { get; set; }
    private List<VentureBlazor.Models.Resource> ResourcesList { get; set; }
    private VentureBlazor.Models.ActivityResource CurrentlyEditedSchedule { get; set; }
    private VentureBlazor.Models.Activity NewActivity = new VentureBlazor.Models.Activity();
    private VentureBlazor.Models.Resource NewResource = new VentureBlazor.Models.Resource();
    private ActivityScheduleRepository repo;
    int selectedValue { get; set; }


    protected override async Task OnInitializedAsync()
    {        
        repo = new ActivityScheduleRepository(ContextFactory.CreateDbContext());
        await LoadSchedules();
    }

    public async Task LoadSchedules()
    {
        SchedulesList = await repo.GetAllActivityResourceSchedulesAsync();
        ActivitiesList = await repo.GetAllActivitiesAsync();
        ResourcesList = await repo.GetAllResourcesAsync();
    }

 public async Task UpdateHandler(GridCommandEventArgs args)
    {        
        await repo.UpdateActivityResourceScheduleAsync((VentureBlazor.Models.ActivityResource)args.Item);
        await LoadSchedules();
    }

}

Enoch
Top achievements
Rank 1
 updated question on 06 Jan 2022
1 answer
246 views

I read the documentation for the grid search bar and it says you can only search for string.

There must be a workaround (:

Should I convert numbers to strings? I only want to search for integers, not decimal numbers.

Nadezhda Tacheva
Telerik team
 answered on 06 Jan 2022
1 answer
912 views
We would like to use the PanelBar but not with a datasounce but instead like kind of a TabStrip with all content defined in markup code and each panel just containing a Blazor component. But it seems like the PanelBar does not work without a data source strangely enough? 
Nadezhda Tacheva
Telerik team
 answered on 05 Jan 2022
0 answers
126 views
Solved
Mohit
Top achievements
Rank 1
 updated question on 05 Jan 2022
1 answer
371 views

Has this been fixed now?

https://feedback.telerik.com/blazor/1471845-allow-control-over-the-popup-edit-form-buttons-at-the-bottom

 

so that we  can now change the texts of buttons in Popup form?

Thanks. 

Marin Bratanov
Telerik team
 answered on 04 Jan 2022
1 answer
453 views
Hi, we are new in Blazor and currently evaluating Telerik UI for Blazor. Simple question how to achieve or similar component like BottomNavigation on ASP.NET Core ??
Marin Bratanov
Telerik team
 answered on 04 Jan 2022
1 answer
328 views

Hi, 

Is there any other way I can scroll the category field in the chart other than the stock chart?

I would like to show only on month's worth of data beyond scroll to generate a chart with one year's worth of materials.

Thank you.

Stamo Gochev
Telerik team
 answered on 03 Jan 2022
1 answer
849 views

Hi,

As the question states, do we need to do this?

A very brief example in REPL: https://blazorrepl.telerik.com/cPlQROaw54hvorQ145

Say I wanted that reference to the button (or any other Telerik Component), to do other things with elsewhere, is the dispose call necessary, or is that totally unnecessary?

Thanks.

Marin Bratanov
Telerik team
 answered on 30 Dec 2021
1 answer
1.6K+ views

Hi. 
I'm wondering if there's a easy way to set a custom order function to a grid column. For example, suppose that I need to sort a column with IP Addresses: 

192.168.168.1
192.168.168.2
192.168.168.101
192.168.168.4
192.168.168.20

Usually the grid sort this column like a string, so the result is: 

192.168.168.1
192.168.168.101
192.168.168.2
192.168.168.20
192.168.168.4

when the desirable result will be: 

192.168.168.1
192.168.168.2
192.168.168.4
192.168.168.20
192.168.168.101

I did several attempts without success. Order by a calculated field created in the column template looks like a workaround more than a real solution. Really don't like it.
Reading about the GridState I've found there is a property: SortCompare (part of SortDescriptor) but I can't make it work assigning a function like this: 

    public class IPAddressComparer : IComparer<IpAddress>
    {
        public int Compare(IpAddress a, IpAddress b)
        {
            return Enumerable.Zip(
                a.Address.Split('.'),
                b.Address.Split('.'),
                (x, y) => int.Parse(x).CompareTo(int.Parse(y)))
                             .FirstOrDefault(i => i != 0);
        }
    }
It seems to be a applicable only for jQuery-based widgets such as UI for ASP.NET MVC. 

What else can I try? Maybe I'm missing something... can't be so complicated. 

Blazorist.
Marin Bratanov
Telerik team
 answered on 30 Dec 2021
Narrow your results
Selected tags
Tags
+? more
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?