Gridview customization

A place for discussion about skinning and design. Before posting questions here you should review the documentation about creating skins.

This thread is closed to new posts. You must sign in to post in the forums.
1/1/2009 1:16:37 PM
Gravatar
Total Posts 55

Gridview customization

Hi, everyone, merry Christmas (with delay  ) and happy new Year!

Well, I'm not quite sure does this belong to development or this forum, but I've a question about customizing web controls look in mojoPortal, especially gridview.

I haven't been able to customize gridview look as much as I would like to (and neither customized control inherited from gridview). For example, I can't set pager to anything else than numbers and I can't get gridview Caption nor EmptyDataText. On the other hand, I did widen gridview and set its colors and fonts via style-gridview.css. As I can see, MP uses web control adapters for customized rendering of gridview and inherited controls. Does this have anything to do with my customization problem or am I simply missing something obvious? I can't get some properties even when using inline design-time declarations (click to smart tag -> Auto Format).

So, what's the best way to achieve further gridview and other controls' customization? Theme.skin?

1/1/2009 1:29:47 PM
Gravatar
Total Posts 18439

Re: Gridview customization

Hi Slaven,

Merry Christmas and Happy New Year to you as well!

I suspect our use of the adapter is related. Our adapter is nothing more than the ASP.NET CSS Control Adapter changed to our namespace.

Actually there are only a few places where we use GridView directly in mojoPortal,most places I'm using YuiGridView which inherits from GridView.

You can disable the adapter by commenting out all references like this in App_Browsers/CSSFriendlyAdapters.browser

<adapter controlType="System.Web.UI.WebControls.GridView"
adapterType="mojoPortal.Web.GridViewAdapter" />

However, it requires a re-compile for changes to take effect.

Alternatively, maybe the link above can provide you enough information to customise it with the adapters enabled. It does produce better quality markup using the adapter.

What I could do is create a custom GridView name mojoGridView that does nothing but inherit from GridView then I could specify the adapter for the mojoGridView without it applying to normal GridView. This way users who want the adapter could use mojoGrdiView and users who don't could use the normal GridView. Currently since I have GridView specified in the .browser file I think it also affects sub classes. Let me know if that would be helpful and if so I will make that change for the next release.

Hope it helps,

Joe

1/1/2009 1:32:09 PM
Gravatar
Total Posts 18439

Re: Gridview customization

I generally recommend not using theme.skin, because any style properties specified there will render as inline style and bulk up the markup, especially on a grid it will produce a lot of redundant inline style.

Best,

Joe

1/2/2009 6:48:27 AM
Gravatar
Total Posts 55

Re: Gridview customization

Hi!

I disabled gridview adapter. It was responsible for some other problems, functional as well as aesthetic. For example, with gridview adapter enabled, every sorting (with header click) reset PageIndex and somehow prevented displaying flexible gridview header & footer when there was no data, so I felt the fastest and most elegant way of dealing with those issues is disabling gridview adapter altogether. It would be easy to keep it disabled even after getting MP's latest version from SVN.

Speaking of proposed mojoGridView class, I don't think it's necessary. A lot of us work with some inherited gridview control anyway. For example, I'm working with gridview inherited from mojoPortal's FlexibleGridView.

However, I have a suggestion. My gridview extends FlexibleGridView in such way that it supports more efficient paging. Ordinary gridview has read-only PageCount property because its paging takes all of records from data source, calculates PageCount, and then discards unnecessary records and displays only those in current gridview page. Wastefull if you ask me, and non-working when you use Linq's Skip and Take methods - or any other classic (non-Linq) smart paging methods.

Object data source can be used in conjunction with gridview and it does have SelectCountMethod property whose result is automatically passed to gridview that databinds to it but such conjunction is rarely used because it supports only the exact way of work as developers in Microsoft have envisioned. If you deviate from this path, object data source becomes veeery clumsy solution for gridview databinding, to say the least.

So I found good article how to implement writable PageCount method here: http://siderite.blogspot.com/2007/08/changing-gridview-pagecount.html and made my own gridview that inherits MP's FlexibleGridView and supports setting PageCount. You could either update MP's FlexibleGridView to implement that or I could send you my inherited gridview. What do you think?

1/2/2009 7:12:15 AM
Gravatar
Total Posts 18439

Re: Gridview customization

Hi Slaven,

Speaking of proposed mojoGridView class, I don't think it's necessary. A lot of us work with some inherited gridview control anyway. For example, I'm working with gridview inherited from mojoPortal's FlexibleGridView.

I think it would be the best solution to make a mojoGridView and extend it with the adapter so you don't have to maintain differences in the .browser file. The problem as I see it is that because we we extend the basic GridView, then all sub classes are also affected whereas if I extend a more specific mojoGridView you can leave it in there and it won't make your sub class use the adapter. Probably with it disabled in your copy then places where I am using GridView are not rendering correctly while your custom stuff may be doing just what you want. By adding a mojoGridView and then replacing my use of GridView with it, then the ones I've created and styled will continue to use the adapter but it won't impact your subclass.

To be honest I don't really use any of the paging abilities of the GridView for the very reasons you mention about efficiency. I retrieve only a page of data from the db and I control the paging with CutePager.

Someone contributed the FlexibleGridView but I don't think it is used anywhere in mojoPortal code. If it will be convenient for you to have your version of it in mojoPortal then we can do that but should probably add it as a sub class like FexibleGridview2 with some notes in the comments about the differences. I don't want to break anything for developers who may already be using the existing one by changing its behavior.

Best,

Joe

1/2/2009 11:09:38 AM
Gravatar
Total Posts 55

Re: Gridview customization

Well, then, if you can make mojoGridView, please do it and announce it somewhere on the forum.

Thanks a lot! 

1/2/2009 11:20:18 AM
Gravatar
Total Posts 18439

Re: Gridview customization

I already created it and updated everything in my sandbox, so next time I merge to trunk (tonight or tomorrow) it will be there. You should not need to change anything in custom code for your own use of GridView unless you do want to use the adapter. By default the standard GridView will no longer use the adapter, so all you will need to do is revert your copy of CSSFriendlyAdapter.browser that you have modified to disable the adapter as it is disabled by default for standard GridView.

In cases where you do want to use the CSS adapter then just use mojoGridView instead of GridView. Its a similar problem and solution as the menu and treeview, we use the CSS adapter also in mojoMenu and mojoTreeview, and standard ASP.nET Menu and Treeview do not use the adapters.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.