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 977091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:50:54+00:00 2026-05-16T03:50:54+00:00

The elegant Action Syntax in the MVCContrib Grid gives us the Empty() method. However,

  • 0

The elegant Action Syntax in the MVCContrib Grid gives us the Empty() method. However, the default behavior of MvcContrib.UI.Grid.GridRenderer<T>.RenderHeader() is to hide the table column headers when the grid is empty. Is there a way to show headers when data is not present that does not require a major refactoring?

Now I have heard of hiding the headers by default and hard-coding something but this is not cool to me.

By the way, this is what is happening under the hood (in MvcContrib.UI.Grid.GridRenderer<T>):

protected virtual bool RenderHeader()
{
    //No items - do not render a header.
    if(! ShouldRenderHeader()) return false;

    RenderHeadStart();

    foreach(var column in VisibleColumns())
    {
        //Allow for custom header overrides.
        if(column.CustomHeaderRenderer != null)
        {
            column.CustomHeaderRenderer(new RenderingContext(Writer, Context, _engines));
        }
        else
        {
            RenderHeaderCellStart(column);
            RenderHeaderText(column);
            RenderHeaderCellEnd();
        }
    }

    RenderHeadEnd();

    return true;
}

protected virtual bool ShouldRenderHeader()
{
    return !IsDataSourceEmpty();
}

protected bool IsDataSourceEmpty()
{
    return DataSource == null || !DataSource.Any();
}
  • 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-05-16T03:50:54+00:00Added an answer on May 16, 2026 at 3:50 am

    In your custom Grid Renderer (subclass GridRenderer<T>) use overrides like these:

    /// <summary>
    /// Renders the <c>table</c> header.
    /// </summary>
    /// <returns>
    /// Returns the negative of the results
    /// of <see cref="GridRenderer<T>.IsDataSourceEmpty"/>.
    /// </returns>
    /// <remarks>
    /// The return value of <see cref="GridRenderer<T>.IsDataSourceEmpty"/>
    /// in this override has no effect on whether the Grid header is rendered.
    /// 
    /// However, this return value is used
    /// by <see cref="GridRenderer<T>.Render"/>
    /// to run <see cref="GridRenderer<T>.RenderItems"/>
    /// or <see cref="GridRenderer<T>.RenderEmpty"/>.
    /// </remarks>
    protected override bool RenderHeader()
    {
        RenderHeadStart();
    
        foreach(var column in VisibleColumns())
        {
            //Allow for custom header overrides.
            if(column.CustomHeaderRenderer != null)
            {
                column.CustomHeaderRenderer(new RenderingContext(Writer, Context, _engines));
            }
            else
            {
                RenderHeaderCellStart(column);
                RenderHeaderText(column);
                RenderHeaderCellEnd();
            }
        }
    
        RenderHeadEnd();
    
        return !base.IsDataSourceEmpty();
    }
    

    …

    protected override void RenderEmpty()
    {
        RenderBodyStart();
        WriteNoRecordsAvailable(base.Writer, this._numberOfTableColumns);
        RenderBodyEnd();
    }
    

    Note that WriteNoRecordsAvailable() is my custom method so it can be ignored.

    Finally:

    /// <summary>
    /// This private member is duplicated
    /// in order to override <see cref="GridRenderer<T>.RenderHeader"/>.
    /// </summary>
    readonly ViewEngineCollection _engines;
    

    …

    /// <summary>
    /// Initializes a new instance of the <see cref="CrmHtmlTableGridRenderer&lt;T&gt;"/> class.
    /// </summary>
    /// <param name="engines">The engines.</param>
    public CrmHtmlTableGridRenderer(ViewEngineCollection engines)
        : base(engines)
    {
        _engines = engines;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would there a more elegant way of writing the following syntax? Thread t0 =
Is there some elegant way to add an empty option to a DropDownList bound
Good evening, I am searching for an elegant solution to implement a transition table
What is an elegant way to sort objects in PHP? I would love to
Is there an elegant way to have performant, natural sorting in a MySQL database?
What is the most elegant way to solve this: open a file for reading,
Is there an elegant way to specialize a template based on one of its
What's a more elegant way of having the code below where i want to
What's an elegant way in Classic ASP to check if session cookies are enabled
Is there an elegant way to create and initialize a const std::vector<const T> like

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.