iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
There is a related sample in this thread: http://www.intersoftpt.com/Community/WebGrid/WebGrid-crash-scrolling-freeze-column-hidden/
When I have no data for the grid, I want to hide all columns, create my own dataset add a row and write the text "no data" into this first row's first column. This is done in the InitializeDataSource event.
In PreRender event I check if there is only this one row with this special text. If yes, I hide all columns (now works after you fixed the crash mentioned in the other thread).
Problem is now that I cannot dynamically enable/disable the column freezing. For normal display, I want the first column to freeze (not modifiable by user). But when I hide all columns when no data is present, I get the error message "Freeze Pane cannot be activated on this column because it has exceeded the maximum size of scrollable viewport."
I assume this is because there is nothing to show (message is probably slightly wrong). So I should disable the frozen columns in the PreRender event somehow. I couldn't get that working. Or leave freezing away in aspx page and enable it for normal data.
In grid's LayoutSettings I have:
I also tried to set/change the value grdResult.LayoutSettings.AllowColumnFreezing. But that caused WebGrid to crash in some JavaScript.
How do I disable/enable column freezing depending on the data I have?
Based on my discussion with the developer, the FreezePane must be enabled or disabled in client side event handler. I am still in the process of simulating the scenario in my environment. I will inform you of any discovery I made.
So how would that work in my example?
Add a dynamic script somehow in PreRender to do that on the client side?
After further testing using the sample code in this thread. You could disable the ColumnFreeezing during page load event. Here is the snippet, only disable the ColumnFreezing if the SelectedValue is C:
protected void Page_Load(object sender, EventArgs e){ if(!Page.IsPostBack) { ddlChoiceA.Items.Add(new System.Web.UI.WebControls.ListItem("A: all columns", "A")); ddlChoiceA.Items.Add(new System.Web.UI.WebControls.ListItem("B: some hidden columns (16-19, 21-22)", "B")); ddlChoiceA.Items.Add(new System.Web.UI.WebControls.ListItem("C: no data", "C")); } if (ddlChoiceA.SelectedValue == "C") grdResult.LayoutSettings.AllowColumnFreezing = ColumnFreezing.No;}
Hi Glenn,
Thanks for your idea. I didn't try it, because I think it cannot work by design - tell me if I'm wrong. What you are doing here is to enable/disable freezing in Page_Load, depending on whether the filter is set to a value that doesn't return data.
We don't know if there is data available or not, just by looking at the filter selection. In this hardcoded sample it might work, but what you are doing here would mean to query the database in Page_Load to see if there is data available or not. Is it that what you intended here?
For me that would mean we have two database requests: one in Page_Load, the other one in grid_InitializeDataSource. One must be enough. Did you want to move this all to the Page_Load event? If yes, then that part is missing. Or did I misunderstand anything?
Any other ideas?
Regards,
Eric
Hii Glenn,
Thanks for clarification. Here some comments from my side:
Two database calls is not an option for two reasons:
Yes, calling the db in OnLoad and caching it somehow, like in a member variable, would be an option. I will consider this. Or remove the freezeing altogether.
But why is PreRender too late? I think this is a design flaw in WebGrid. Before the PreRender event, no data should get rendered to the client. And enabling/disabling column freezing, which can also be done on the client-side, is clearly a rendering issue. Don't you agree with this?
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname