Telerik Forums
UI for Blazor Forum
2 answers
416 views

I have built my own component, GenericGrid, which under the hood uses a TelerikGrid. The GenericGrid takes TItem as typeparam which gets passed onto a generic HTTP method that retrieves records from an OData API based on the TItem that gets passed on.

GenericGridTest.razor:

@page "/GenericGrid" @using IndiciaStage.Domain.Entities <GenericGrid TItem="Employee"></GenericGrid> @code { }

 

GenericGrid.razor:

@using Indicia.Grid.Services
@using System.Collections.ObjectModel
@using IndiciaStage.Domain.Entities

@inject LocalStorageService _localStorage
@inject GenericHttpEntityService _entityService

@typeparam TItem

<TelerikGrid @ref="@Grid"
             AutoGenerateColumns="true"
             Height="460px"
             RowHeight="60"
             PageSize="10"
             Pageable="true"
             Sortable="true"
             Resizable="true"
             FilterMode="GridFilterMode.FilterMenu"
             EditMode="GridEditMode.Popup"
             OnRead="@ReadEntity"
             OnStateInit="@((GridStateEventArgs<object> args) => OnStateInitHandler(args))"
             OnStateChanged="@((GridStateEventArgs<object> args) => OnStateChangedHandler(args))">
    <GridColumns>
        <GridAutoGeneratedColumns />
    </GridColumns>
</TelerikGrid>


@code {
    // Grid data
    private List<TItem> GridData { get; set; } = new();
    private int Total { get; set; }
    
    // Parameters
    [Parameter]
    public TItem Entity { get; set; }

    private async Task ReadEntity(GridReadEventArgs args)
    {
        var data = await _entityService.GetAll<TItem>(args.Request);

        GridData = data.Records;
        Total = data.Total;

        StateHasChanged();
    }

 

EntityListResponse.cs (based on the OData Grid sample on GitHub, made generic):

    public class EntityListResponse<T>
    {
        [System.Text.Json.Serialization.JsonPropertyName("value")]
        public List<T> Records { get; set; }
        
        [System.Text.Json.Serialization.JsonPropertyName("@odata.count")]
        public int Total { get; set; }
    }

 

GetAll method in GenericHttpEntityService.cs:

        public async Task<EntityListResponse<T>> GetAll<T>(DataSourceRequest request)
        {
            var name = typeof(T).Name;
            var baseUrl = $"{name}s?";

            var requestUrl = $"{baseUrl}{request.ToODataString()}";

            var requestMessage = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            requestMessage.Headers.Add("Accept", "application/json");
            var client = HttpClient.CreateClient("IndiciaStageApi");
            var response = await client.SendAsync(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                var body = await response.Content.ReadAsStringAsync();

                var options = new JsonSerializerOptions();
                options.Converters.Add(new JsonStringEnumConverter());
                var oDataResponse = JsonSerializer.Deserialize<EntityListResponse<T>>(body, options);

                return oDataResponse;
            }
            else
            {
                throw new HttpRequestException(
                    "Request failed. I need better error handling, e.g. returning empty data.");
            }
        }

 

What I want to achieve is for the grid columns to be generated automatically based on the object type, Employee in this case, and the retrieved data to be bound to the grid. Sadly, this doesn't seem to work

As you can see, the JSON is deserialized correctly into an EntityListResponse of type Employee. However, I don't know how to bind the data to the grid and autogenerate its corresponding columns. I tried adding Data="@GridData" to the TelerikGrid, but that returns an error because the type of GridData is List<TItem>.

Is there any way to implement what I'm trying to achieve?

Radko
Telerik team
 answered on 28 Sep 2021
1 answer
1.4K+ views

Hi,

I was wondering what is the best approach to strip out the HTML of a text field that is displayed in a Blazor Datagrid.

I tried using the Template feature along with MarkupString as shown below but it just returns the name of the field rather than the contents of it.

<TelerikGrid Data="Model.CurrentPageData" TotalCount="Model.TotalItemCount" OnRead="ReadItems" Pageable="true" PageSize="10" Groupable="true" Sortable="false">
    <GridColumns>
        <GridColumn Field="@(nameof(Escalation.EscalationId))" Title="Escalation ID" Width="120px" />
        <GridColumn Field="@(nameof(Escalation.CaseType))" Title="Type" Width="120px" />
        <GridColumn Field="@(nameof(Escalation.SummaryOfRequest))" Title="Request Summary" Width="120px" />
            <Template>
                    @((MarkupString)(nameof(Escalation.SummaryOfRequest)))               
            </Template>
        </GridColumn>
        <GridColumn Field="@(nameof(Escalation.PrimaryBu))" Title="Primary BU" Width="120px" />
        <GridColumn Field="@(nameof(Escalation.CreatedDate))" Title="Created" DisplayFormat="{0:dddd, dd MMM yyyy}" Width="120px" />
    </GridColumns>
</TelerikGrid>


Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
 answered on 28 Sep 2021
2 answers
1.2K+ views

 

Currently, I am using Listview for binding, Whereas I couldn't able to bind the selected Value in the list.

Hence, I need Dual ListBox for moving data from one listbox to another one.

Could you please on this.

 

 

Thanks

Vishnu

Nadezhda Tacheva
Telerik team
 answered on 27 Sep 2021
1 answer
1.6K+ views

Hello, 

I have the following data model which I want to display in TelerikGrid.

The columns should be Name, Price (which is easy), but I also want to display the topping columns, where each caption is the key of the dicionary entry and the displayed value should be the value from the dictionary entry:

Expected result:

Name     |    Price      |      Tomato       |    Cheese       |     Bacon

Cheese  |   8.99         |     low               |   very much   |   no

Tomato  |   5.99        |     very much   |  not so much  |   no

Bacon     |   10.99      |     low               |  not so much  |   three pieces

 

Is that possible by using the TelerikGrid and how should the data binding look like ?

I took the sample code from the expando sample to create the columns based on the dictionary entries

but I didn't get the values from the dictionary to display each value in the rows.

 

public class Pizza
    {
        public string Name { get; set; }

        public decimal Price { get; set; }

        public IDictionary<string, string> Toppings { get; set; }


        public static IList<Pizza> PizzaRecipies()
        {
            return new List<Pizza>()
            {
                new Pizza()
                {
                    Name = "Cheese",
                    Price = 8.99M,
                    Toppings = new Dictionary<string, string>()
                    {
                        {"Tomato","low"},
                        {"Cheese", "very much"},
                        {"Bacon", "no"}
                    }
                },
                new Pizza()
                {
                    Name = "Tomato",
                    Price = 5.99M,
                    Toppings = new Dictionary<string, string>()
                    {
                        {"Tomato","very much"},
                        {"Cheese", "not so much"},
                        {"Bacon", "no"}
                    }
                },
                new Pizza()
                {
                    Name = "Bacon",
                    Price = 10.99M,
                    Toppings = new Dictionary<string, string>()
                    {
                        {"Tomato","low"},
                        {"Cheese", "not so much"},
                        {"Bacon", "three pieces"}
                    }
                }

            };
        }
    }


Radko
Telerik team
 answered on 27 Sep 2021
1 answer
292 views

Great to see the new Gantt feature in update 2.26.  We immediately starting implementation for tracking our publishing stages at Microsoft for shipping software updates to show the parallelism of the processes and easily identify the relative time each stage takes.  This is a great improvement over a list in a table.   

Sadly, the current implementation of Gantt only supports days whilst our publishing stages take only a few minutes or hours.

I'm hoping additional support for a minutes view is coming soon as we had to shelve implementation of a Gantt view of publishing stages using your Gantt chart for the time being.  If it's not coming, an announcement of it's in the road map plan or not coming would be greatly appreciated by your marketing team.

Nadezhda Tacheva
Telerik team
 answered on 27 Sep 2021
1 answer
241 views

Where a DropDownList is populated dynamically, and mandatory, it makes sense for there to be an option to automatically default to the first item in the list.  Especially as there may only be one item in the list, or the first item may account for 99% of cases.

It would be great if this could be done via a simple property:  DefaultToFirst="true".

Svetoslav Dimitrov
Telerik team
 answered on 27 Sep 2021
1 answer
327 views
I have a project with a grid and a context menu.  When I right click on a grid cell, I create a contextual menu based on the name in the grid row.  Then when I run the await ContextMenuRef.ShowAsync(mouseEventArgs.ClientX, mouseEventArgs.ClientY); command, the menu is from the previous right click and previous row.  The actions performed based on the menu choice happen for the right row but the menu itself, it shows previous values.  I have included my mock project for your perusal.  Click on Invoices to get to the page with the problem.
Radko
Telerik team
 answered on 24 Sep 2021
1 answer
221 views

Hi everybody,

What I would like to achieve is to split a container in 2 halfs, then after selecting one of the two halfs to have the posibility to split the selected half agin in other two halfs, and so on.

I was thinking to use the Splitter component for this kind of things having two buttons: one for splitting vertically, and one for splitting horizontally which when one is pressed do the split of the selected container, but I can't understand how can I do this because in all your examples the splitters are already defined. How can this be done dynamically?

Can anyone help me?

Best regards.
Cipri

Nadezhda Tacheva
Telerik team
 answered on 24 Sep 2021
1 answer
577 views

How to know while viewing styles in Chrome Dev tools which .k style classes to need to be overridden for margins using CSS isolation.

Also if using properties of the TelerikNotification HorizontalPosition set to center and VerticalPosition set to top what is needed to override the top position when using CSS isolation

Eric R | Senior Technical Support Engineer
Telerik team
 answered on 23 Sep 2021
0 answers
681 views

I am struggling with getting the dropdown part of Dropdownlist to match.

The dropdown part is to small. If I remove bootstrap then it's to far to the right.

Have also tried to put the DropDownList outside the grid. Same result.

Setting the width doesn't help

See the pictures.

I have measured the computed values of the animation container and the values are correct. So something else is overwriting the css.

I removed all stylesheets except _content/Telerik.UI.for.Blazor/css/kendo-theme-default/all.css


Code

@page "/DepartmentAccess"
<h3>DepartmentAccess</h3>

<TelerikGridLayout>
    <GridLayoutColumns>
        <GridLayoutColumn Width="300px"></GridLayoutColumn>
        <GridLayoutColumn Width="200px"></GridLayoutColumn>
        <GridLayoutColumn Width="300px"></GridLayoutColumn>
    </GridLayoutColumns>
    <GridLayoutRows>
        <GridLayoutRow></GridLayoutRow>
        <GridLayoutRow></GridLayoutRow>
        <GridLayoutRow></GridLayoutRow>
    </GridLayoutRows>
    <GridLayoutItems>
        <GridLayoutItem Column="1" Row="1">Department</GridLayoutItem>
        <GridLayoutItem Column="1" Row="2">
            <div>
                <TelerikDropDownList
                    TValue="int"
                    TItem="CboItem"
                    Data="UserDepartments"
                    TextField="Name"
                    ValueField="Id"
                    Filterable="true"
                    FilterOperator="StringFilterOperator.Contains"
                    DefaultText="Select Department"
                    ValueChanged="@(UserDepartmentSelected)"
                    PopupHeight="400px"
                    />
            </div>
        </GridLayoutItem>
        <GridLayoutItem Column="1" Row="3">Listbox with selected funds for selected department</GridLayoutItem>
        <GridLayoutItem Column="2" RowSpan="3">add / remove buttons</GridLayoutItem>
        <GridLayoutItem Column="3" Row="1">Avaiable funds</GridLayoutItem>
        <GridLayoutItem Column="3" Row="2">Listbox wit avaiable funds</GridLayoutItem>
    </GridLayoutItems>
</TelerikGridLayout>

Martin Herløv
Top achievements
Rank 2
Bronze
Iron
Iron
 updated question on 23 Sep 2021
Narrow your results
Selected tags
Tags
+? more
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?