Grid without header row

233 views
Skip to first unread message

jeroenh

unread,
Oct 28, 2009, 4:32:31 PM10/28/09
to mvccontrib-discuss
I'm trying to find out how to hide the header row in the grid. Is this
possible?

Thanks!
jeroen

Jeremy Skinner

unread,
Oct 28, 2009, 4:37:14 PM10/28/09
to mvccontri...@googlegroups.com
Hi Jeroen,

You'll need to create a custom GridRenderer to do this. Create a class that inherits from MvcContrib.UI.Grid.HtmlTableGridRenderer<T> and override the RenderHeader method. You can then pass your custom GridRenderer to the grid's RenderUsing method.

Jeremy


2009/10/28 jeroenh <jeroen.h...@gmail.com>

jeroenh

unread,
Oct 28, 2009, 4:53:42 PM10/28/09
to mvccontrib-discuss
Hi Jeremy,

Thanks for your reply.

> You'll need to create a custom GridRenderer to do this. Create a class that
> inherits from MvcContrib.UI.Grid.HtmlTableGridRenderer<T> and override the
> RenderHeader method. You can then pass your custom GridRenderer to the

What I did:

public class GridWithoutHeaderRenderer<T>:
MvcContrib.UI.Grid.HtmlTableGridRenderer<T> where T : class
{
protected override bool RenderHeader()
{
return false;
}
}

However, this results in no table rendered at all... Any clues?

thanks,
jeroen

Jeremy Skinner

unread,
Oct 28, 2009, 4:55:34 PM10/28/09
to mvccontri...@googlegroups.com
You need to return true - the return value of RenderHeader indicates whether rendering should continue afterwards. By overriding RenderHeader you've already stopped the header from rendering, so you now need the GridRenderer to continue rendering the rest of the table.

Jeremy

2009/10/28 jeroenh <jeroen.h...@gmail.com>

jeroenh

unread,
Oct 28, 2009, 5:08:47 PM10/28/09
to mvccontrib-discuss
Yes, I found that out myself in the mean time. However, returning
false was not the main problem (It should still have rendered the 'no
data' line).

The main issue was that I *replaced* the 'Render()' call with
'RenderUsing(new MyCustomRenderer())'.

So for future reference: when you need to use a custom grid renderer
this is the syntax:

Html.Grid(items).Columns(...).RenderUsing(new MyCustomRenderer
()).Render();

thanks again,
jeroen

On 28 okt, 21:55, Jeremy Skinner <jer...@jeremyskinner.co.uk> wrote:
> You need to return true - the return value of RenderHeader indicates whether
> rendering should continue afterwards. By overriding RenderHeader you've
> already stopped the header from rendering, so you now need the GridRenderer
> to continue rendering the rest of the table.
>
> Jeremy
>
> 2009/10/28 jeroenh <jeroen.haegeba...@gmail.com>

Jeremy Skinner

unread,
Oct 28, 2009, 5:10:27 PM10/28/09
to mvccontri...@googlegroups.com
Ah, yes the call to Render is indeed necessary if you're using the ActionSyntax.

If you're using the regular syntax, then it is optional.

Jeremy

2009/10/28 jeroenh <jeroen.h...@gmail.com>
Reply all
Reply to author
Forward
0 new messages