Completed
Last Updated: 30 Jun 2020 06:55 by ADMIN
Release 2.15.0
Alden
Created on: 16 Jul 2019 07:13
Category: Grid
Type: Feature Request
38
Bind to DataTable

ADMIN EDIT: Check the source code and comments in it from the following demo to see how to bind the grid to a DataTable: https://demos.telerik.com/blazor-ui/grid/data-table. You can also examine it offline - the entire demos project is available in the "demos" folder of your installation

 

 

I would like to be able to supply a DataTable with an arbitrary amount of columns to the grid and display them all without declaring them all. This should also allow paging, sorting, filtering. At the moment binding to a DataTable is not supported, only IEnumerable collections are.

At the moment, here's the closest I can get, sorting and filtering throw errors so they are disabled.

 

@using System.Data
@using Telerik.Blazor
@using Telerik.Blazor.Components.Grid
 
<button class="btn btn-primary" @onclick="@LoadData">Load Data</button>
 
@if (@d != null)
{
    <TelerikGrid Data=@d.AsEnumerable() TItem="DataRow"
                 Sortable="false" Filterable="false" Pageable="true" PageSize="3"
                 Height="400px">
        <TelerikGridColumns>
            @foreach (DataColumn col in d.Columns)
            {
                <TelerikGridColumn Field="@col.ColumnName" Title="@col.ColumnName">
                    <Template>
                        @((context as DataRow).ItemArray[col.Ordinal].ToString())
                    </Template>
                </TelerikGridColumn>
            }
        </TelerikGridColumns>
    </TelerikGrid>
}
 
@functions {
    DataTable d = null;
 
    void LoadData()
    {
        d = GetData();
    }
 
    public DataTable GetData()
    {
        DataTable table = new DataTable();
 
        table.Columns.Add("Product", typeof(string));
        table.Columns.Add("Price", typeof(double));
        table.Columns.Add("Quantity", typeof(int));
        table.Columns.Add("AvailableFrom", typeof(DateTime));
 
        table.Rows.Add("Product 1", 10.1, 2, DateTime.Now);
        table.Rows.Add("Product 2", 1.50, 10, DateTime.Now);
        table.Rows.Add("Product 3", 120.66, 5, DateTime.Now);
        table.Rows.Add("Product 4", 30.05, 10, DateTime.Now);
 
        return table;
    }
}

 

17 comments
ADMIN
Marin Bratanov
Posted on: 30 Jun 2020 06:55

Hello Ben,

The documentation for this is in the code comments in the demo. The proper Blazor way is to use models and I recommend people consider that option if they can.

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Ben Hayat
Posted on: 29 Jun 2020 21:49
Is there any documentation on the DataTable? The demo doesn't really provide much details. There is nothing in the docs.
ADMIN
Marin Bratanov
Posted on: 28 Jun 2020 09:51

Hello everyone,

Check the source code and comments in it from the following demo to see how to bind the grid to a DataTable: https://demos.telerik.com/blazor-ui/grid/data-table. You can also examine it offline - the entire demos project is available in the "demos" folder of your installation

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
ADMIN
Marin Bratanov
Posted on: 17 Jun 2020 15:48

Yes, both will be available in the 2.15.0 release that is planned for the end of the month.

--Marin

Robert
Posted on: 17 Jun 2020 15:45
Excellent news. Does that mean we can expect this item (binding to expando object) to be completed soon as well?
https://feedback.telerik.com/blazor/1429858-please-add-support-for-binding-grids-to-dynamic-expandoobject
Robert
Posted on: 10 Jun 2020 07:12
Thank you.
I know this is not a trivial task (no one said it was) but it is good to know that you are working on it.

ADMIN
Marin Bratanov
Posted on: 10 Jun 2020 07:10

Hello Robert,

This feature is by far not a trivial one. We are working on it among other things and if all is well it will make it into 2.15.0 which his planned for the end of June.

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Robert
Posted on: 10 Jun 2020 07:04

Hi,

are there any updates? It's in "Planned" for a while now. 
When can we expect v 2.15.0 ?


Best regards

Brenon
Posted on: 16 Apr 2020 13:42
Thanks Marin for the update.  We look forward to it!
ADMIN
Marin Bratanov
Posted on: 16 Apr 2020 13:41

Yes, this is on our roadmap, and we intend to work on this. Clicking the Follow button on the page will ensure you get notifications when there is a change.

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Brenon
Posted on: 16 Apr 2020 12:16
Alden that is a good solution for rendering the data but doesn't provide the sorting/filtering/editing functionality of the Telerik grid all of which we need for our application.  I'm hoping that since this is marked as "Planned" that it is on the roadmap for an upcoming release.
Alden
Posted on: 15 Apr 2020 21:29

I've looked extensively at a lot of libraries and I have not found a single control that's capable of displaying a plain DataTable in a way that makes sense. Here is what I do instead.

I declare a List<Dictionary<string, string>> and then render that to the browser as a table. It contains only enough rows that can be displayed at any one time on the screen.  The first row is always the column names.  If I set overflow-x:scroll as the style, then horizontal scrolling works fine.  However, you must set some pager controls to step vertically through the DataTable rows, re-rendering the List each step, because you can't vertically scroll without losing your column headers, nor can you render a seperate column header table and keep them aligned without getting involved with JavaScript.  So far, I have a single line of unavoidable JavaScript in my entire multi-screen web application with dozens of controls, and that's it.

It took a LOT of experimentation to arrive at the above design, but it works.  There may have been some development on this recently, but as far as I can tell this is a pretty stable solution.

Seth
Posted on: 15 Apr 2020 21:14
This would be a huge plus++ for us!
Brenon
Posted on: 15 Apr 2020 20:47
Is there any update on this?  We would find this extremely useful in our application.
ADMIN
Marin Bratanov
Posted on: 21 Nov 2019 08:08

You can click the Follow button at the top of the page to get email notifications for status changes. At this point, I cannot provide a time frame.

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
l
Posted on: 21 Nov 2019 08:07
Is there a prediction of when support for ADO DataTable will be provided?
Thank you
Dan
Posted on: 26 Sep 2019 13:39
This, or binding to an IEnumerable without having to statically define the columns would be greatly appreciated. I need to be able to support different "views" dynamically.