I have created a form that uses an ASPxGridView. The datasource for the gridview is set dynaimcally based on the table selected by the user. There are 2 separate issues I have found when dynamically setting the datasource properties.
Some of the tables have in excess of 20 million records, so it is important that apply filters directly on the datasource, and i need the filter expression from the ASPxGridView to send to the datasourceobject.
Issue 1
The first problem is that any changes to the Filters do not seem to apply to the GridViews FilterExpression property until well after the expression is useful. It is available in the ProcessColumnAutoFilter event but only when it is initially set, if you clear the filter field or remove all filters, the filter expression still contains the previous expression, even inside the ProcessColumnAutoFilter event. In fact I have wired into every event exposed by the gridview and i never see the FilterExpression property get cleared. Since the filter expression doesn't get cleared I am unable to tell that the filter has been removed and my datasource continues to retrieve a filtered dataset. In addition all of this happens after the grid has been databound which is too late to make it useful anyway unless you want to accept the overhead of binding your gridview twice on each callback. Is there any way to determine the actual filters that are applied when they are useful to the user, somewhere in the page load or anywhere before the databinding of the grid?
Issue 2, when setting the datasource dynamically, I group the records, by any of the selected fields, when I attempt to expand the group the grid resets. I am sure this has to do with my rebinding of the grid inside PageLoad but as far as i can tell, there is no way to determine if the callback is from a grouping command or not, so i have no indicator to help me determine if the grid needs to be rebound. I could use some direction on this issue.
Steps to Reproduce:
Issue 1
Part 1) Set a breakpoint inside any event that occurs before the gridview gets bound. Apply a filter to the gridview (I use the category name field in the categories table) when reaching your breakpoint, view the gridviews filter expression and you can see it does not get updated with the applied filter.
Part 2) Apply a filter, Remove the filter. Set a breakpoint anywhere during the callback that occurs when clearing the filter, at no point during the page cycle of the callback does the filter expression show that the filter has been removed
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
I have resolved Issue 2, this was happening because i was clearing and readding the gridview columns on each postback.
Just for continuity sake and for others who may want to take this approach, I am uploading the version with the updates after Issue 2 was resolved.
Hello Aaron,
Thank you for the information. To my understanding, you've solved your issue completely. If I'm mistaken, feel free to reactivate the report.
Thanks,
Vest
The filter issue still remains (and there are 2 parts to it though they are completely related).
Part 1) There is no way for me to get the gridviews active filters on a callback at any time before i bind the gridview, as the gridview's filter expression is not correct at any point before the gridview is bound. Is there any way for me me to retrieve the active filters from the gridview (a correct filter expression) before the gridview is bound on a callback?
Part 2) At no point does the grid views filter expression get updated to indicate that the filter has been removed. At least when adding a filter i can see the filter expression get updated in the ProcessColumnAutoFilter (albeit this is too late to be useful when trying to use the filter expression to filter directly on the datasource), however when you remove a filter the filter expression never gets updated during the callback, not even during the ProcessColumnAutoFilter event.
Truely there is only 1 issue here. The gridview filterexpression is inaccurate during a callback, and it would be extremely beneficial to be able to retrieve an accurate filter expression somewhere early in the page lifecycle during a callback (preferrably PageLoad or OnInit)
Hi Aaron,
The valid FilterExpression value should be available within the ASPxGridView's DataBound event handler. Please explain what you wish to achieve and we will let you know how this should be done.
Thanks,
Plato
Yes an accurate filter expression should be available in the gridview databound event, however if you had run the project i had supplied you would see that it is not. The supplied project already has the databound event pre wired up for you. Simply set a breakpoint inside the databound event, run the project, add a filter to the category name field and then analyze the filter expression when the databound event fires, it is empty. Then remove the filter and analyze the filter expression in the databound event again, you will see that the filter you are removing is now contained in the filter expression (when it should not be, because the filter is being removed).
In addition, it may be by design that the filter expression is "intended to be" available in the databound event, but wouldn't it make more sense to make this available pre databinding so that the filter expression could be used to filter a datasource pre databinding and the developer doesnt have to bind to the datasource, retrieve the filter expression, then filter the datasource, then rebind the gridview?
As for explaining what i am trying to do, I am trying to use the filter expression of the gridview to filter directly on the datasource so that i can limit my result set, however since the filter expression is incorrect this is not possible.
Hi Aaron,
Sorry, I misinformed you. The new FitlerExpression is parsed after the grid is bound to its DataSource. This is the correct behavior, as the current grid state should correspond to its properties. So, if the FilterExpression is set, the grid should already be filtered. This can be done only after the grid is bound to its data source.
The correct solution to this task is described in the GridView loaded from Sqlserver Store Procedure with filter parameters thread.
Thanks,
Plato
Not sure what part of that link is supposed to help me. I use server mode with xpo data sources in other applications, however this application is intended to give users access to tables that will be added on the fly. I have no intention of opening my project and regenerating persistent classes, rebuilding and going through the long process to get a deploy done in this company when it is completely unnecessary to do so.
If the ProcessColumnAutoFilter event is supposed to help, then as i said in my very first post, when removing a filter from the gridview the filter expression remains incorrect even in the ProcessColumnAutoFilter event !!!
You may say this is by design, but it is a poor design indeed, and I truely doubt that exposing an accurate filter expression prior to or even during the databound event would cause your gridview to come crashing to its knees. I Imagine I will have to use a hack and analyze the "__CALLBACKPARAM" to truely see what filters are applied, though this truely seems ridiculous.
Hi Aaron,
The FilterCondition is available when the BeforePerformDataSelect event is raised by the grid and Selecting event of the DataSourceControl. So, you should be able to change the
datasource's where clause based on the ASPxGridView's FilterExpression. If you wish, I will write a project showing this approach.
Thanks,
Plato
That would be great, but it would be more helpful if you could tell me why that approach doesn't work in the sample i provided. The project I sent you doesn't capture the BeforePerformDataSelect event, but this morning I added that event to my local copy of the provided sample project and again verified that the Filter expression is incorrect even inside the BeforePerformDataSelect handler. The filter expression is always lagging. When i add a filter, the filter expression is empty, remove the same filter, then the filter shows up in the filter expression. add 2 filters and only the first one shows up.
Perhaps it is how the project is structured. I currently have a hack in place in my project, pulling the filters from __CALLBACKPARAM
in page load , though i have to do a translation from the column index which seems to be embedded with some other identifier. I can see that, since you are passing the column index instead of the column name in the callback parameters, that you would have to have the grid be bound to retrieve the column name to update the filter expression correctly, but I have wired into all of these events and none of them provide me with an accurate filter expression.
Again the only time I get some glimpse of an accurate filter expression is inside the ProcessColumnAutoFilter event handler. I can identify when a filter gets added, unfortunately the filter expression doesn't get updated correctly when you actually remove a filter.
Thanks
Hi Aaron,
First, please accept my apologies for the delay in answering. I need some additional time to research the problem. I'll do my best to give you a solution soon.
Thanks,
Plato
Hi Aaron,
Your code does not work properly because you call the DataBind method too early. The FilterExpression becomes available when the ICallbackEventHandler.RaiseCallbackEvent method is called and this happens later than the Page_Load. I have changed your code slightly, and now the ASPxGridView contains the correct FilterExpression within BeforePerformDataSelect event handler.
I should also mention that the AccessDataSource.FilterExpression is applied on the web server and it is not passed to the DB server…
Thanks,
Plato
You guys rock!!! I was able to integrate your modifications into my production application. Thank you very much for taking the time to resolve help me with this issue.