Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8115805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:35:08+00:00 2026-06-06T03:35:08+00:00

I have a telerik grid with a dynamic data source (the grid may use

  • 0

I have a telerik grid with a dynamic data source (the grid may use up to roughly 10 totally different models for its data), so I have to build the columns dynamically as well (obviously). One of the columns in the grid (with certain models) is a double representing a time span in milliseconds. What I want to do is format this double to look like a timespan.The telerik code looks like this:

<% Html.Telerik()
     .Grid(Model.DynamicGridDataSource)
     .Name("statisticalGrid")
     .Columns(a => GridHelper.GenerateColumns(a, Model.SelectedReport))
     .DataBinding(dataBinding => dataBinding.Ajax().Select("_SelectGrid", "Reports", new { reportId = Model.ReportId, dateFrom = Model.DateFrom, dateTo = Model.DateTo, date = Model.Date, AvailablePlans = Model.AvailablePlans }))
     .Sortable(GridSortSettingsBuilder => GridHelper.SortColumns(GridSortSettingsBuilder,
                                            Model.DynamicGridDataSource.GetType(),
                                            Model.SelectedReport))
     .Filterable()
     .Pageable(page => page.PageSize(25))
     .Reorderable(reorder => reorder.Columns(true))
     .Groupable
     (
         groupingSettingsBuilder => GridHelper.GroupColumns(groupingSettingsBuilder,
                                    Model.DynamicGridDataSource.GetType(),
                                    Model.SelectedReport)
     )
     .ClientEvents(events => events
          .OnColumnReorder("onReorder"))
     .Render();

and GridHelper.GenerateColumns looks something like this:

public static void GenerateColumns(GridColumnFactory<dynamic> columnFactory, Company.Product.Data.Entity.Report reportStructure)
        {
            foreach (var columnLayout in reportStructure.ReportCols.OrderBy(o => o.ColumnSequence))
            {
                var columnBuilder = columnFactory.Bound(columnLayout.ColumnType);

                if (columnLayout.ColumnType.Equals("SessionLength") ||
                 columnLayout.ColumnType.Equals("AverageTime") ||
                 columnLayout.ColumnType.Equals("TotalTime") ||
                 columnLayout.ColumnType.Equals("CallTime"))
                {
                    // disable grouping
                    columnBuilder.Groupable(false);
                    string dataBindProperty = columnLayout.ColumnType;
                    if (columnLayout.DataFormat == "{0:T}")
                    {
                        //Even though the format looks like time ({0:T}), its actually a double which needs to be formatted here to look like a TimeSpan
                    }

                }

                if (!string.IsNullOrEmpty(columnLayout.Label))
                {
                    columnBuilder.Title(columnLayout.Label);
                }

                if (columnLayout.DataFormat != null && columnLayout.DataFormat == "{0:P}")
                {
                    columnBuilder.Format("{0:P}");
                }

                if (columnLayout.SumIndicator)
                {
                    if (columnLayout.DataFormat == "{0:T}")
                    {
                        AddAggregateToColumnTimeSpan(columnBuilder, Aggregate.Sum);
                    }
                    else
                    {
                        AddAggregateToColumn(columnBuilder, Aggregate.Sum);
                    }
                }

                if (columnLayout.HideIndicator)
                {
                    columnBuilder.Column.Hidden = true;
                }

            }
        }

I was able to format the footer correctly, but I didn’t know how to format the rest of the column, since out of the context of the telerik code I don’t have access to the item iterator or anything. Any suggestions/ideas? Maybe columnFactory.Bound(columnType).Format(/*something*/)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:35:09+00:00Added an answer on June 6, 2026 at 3:35 am

    You said, “the grid may use up to roughly 10 totally different models for its data”, so perhaps instead of trying to represent all those models in one grid, you have one grid for each model. You could put each grid in it’s own partial view with the main view using some mechanism for deciding which partial view to load. Here is a simple example.

    Controller

    public ActionResult DynamicReport
    {
        //Get your Model
        Model.model1 = model_01 = Model.DynamicGridDataSource.GetDynamicModel()
        //Get the name of what model is being returned so view knows which 
        //partial view to load
        ViewBag.Message = model_01.Name
        ...
    
        return View(model_01)
    }
    

    In the view have some conditional logic to chose which partial view to load.

    View

    <h2>View</h2>
    @{
      string pView = "~/Views/Grid/Partial_01.cshtml";
      switch(ViewBag.Message)
      {
          case "p02":
          pView =  "~/Views/Grid/Parital_02.cshtml"
          break;
          .....
      }
    }
    
    @Html.Partial(pView)
    

    PartialView_01

    @model List<Models.Misc>
    @(Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
          columns.Bound(a => a.Id).Width(120);
          columns.Bound(a => a.Name).Width(100);
          columns.Bound(a => a.Value).Format("{0:#,##0.00}").Width(100).Title("Price");
        })
    )
    

    PartialView_02

    @model List<Models.Temp>
    @(Html.Telerik().Grid(Model)
      .Name("Grid")
      .Columns(columns =>
      {
        columns.Bound(o => o.Name)
                .Aggregate(aggregates => aggregates.Count())
                .FooterTemplate(@<text>Total Count: @item.Count</text>)
                .GroupFooterTemplate(@<text>Count: @item.Count</text>);
    
        columns.Bound(o => o.Start)
                .Template(@<text>@item.Start.ToShortDateString()</text>)
                .Aggregate(aggreages => aggreages.Max())
                .FooterTemplate(@<text>Max: @item.Max.Format("{0:d}")</text>)
                .GroupHeaderTemplate(@<text>Max: @item.Max.Format("{0:d}")</text>)
                .GroupFooterTemplate(@<text>Max: @item.Max.Format("{0:d}")</text>);
    
        columns.Bound(o => o.Value)
                .Width(200)
                .Aggregate(aggregates => aggregates.Average())
                .FooterTemplate(@<text>Average: @item.Average</text>)
                .GroupFooterTemplate(@<text>Average: @item.Average</text>);
    
        columns.Bound(o => o.tsMilliseconds)
              .Width(100)
              .Aggregate(aggregates => aggregates.Sum())
              .Template(@<text>@TimeSpan.FromMilliseconds(@item.tsMilliseconds)</text>)
              .Title("TimeSpan")
              .FooterTemplate(
              @<text>
                    <div>Sum: @TimeSpan.FromMilliseconds(@Convert.ToDouble(@item.Sum.Value.ToString())) </div>
                </text>)
          //header if you group by TimeSpan
              .GroupHeaderTemplate(@<text>@item.Title: @item.Key (Sum: @TimeSpan.FromMilliseconds(@Convert.ToDouble(@item.Sum.Value.ToString())))</text>)
          //footer for grouping
              .GroupFooterTemplate(@<text>Sum: @TimeSpan.FromMilliseconds(@Convert.ToDouble(@item.Sum.Value.ToString()))</text>);
      })
        .Sortable()
        .Groupable(settings => settings.Groups(groups => groups.Add(o => o.Start)))
    ) 
    

    And so on, for each different model. With each model having its own partial view you can easily format each grid to fit its model while still having only one main view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid with a column which contains a nullable data Html.Telerik().Grid(Model) .Columns(columns
In Index.cshtml I have the following: @{ Html.Telerik().Grid<hekomaseru.Models.testdbEntities1>(testtable) .Name(grid1) .Pageable() .Sortable() .Filterable() .Groupable() .Render();
i have this line of code in my view using the Telerik Grid: columns.Bound(o
I have the following markup. @(Html.Telerik().Grid(Model) .Name(Grid) .DataKeys(keys => keys.Add(key => key.Id)) .Columns(columns =>
I have this in my code: @model Tuple<IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>> @(Html.Telerik().Grid(Model.Item3) .Name(Grid) .DataKeys(keys =>
I have to display data using the telerik grid (master / detail) . Is
I have a Telerik Grid, with two columns I need to keep second column
I have a Telerik Grid which has a footer that needs to display column
I have a telerik grid in which i have a column where i show
We have a Telerik Grid (i.e. enhanced version of ASP.Net vanilla grid). On some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.