We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Given a DataTable source, show only filter results

Given a DataTable as the DataSource, how can I tell the GridGroupingControl to only show rows where "[Level] LIKE ''Verbose''"? Is there a way to apply such a filter to the DataTable and/or the GridGroupingControl? Thanks!

9 Replies

AD Administrator Syncfusion Team March 15, 2004 06:41 AM UTC

You add a RecordFilterDescriptor to the TableDescriptor''s RecordFilters collection. //filter states that start with N RecordFilterDescriptor filter = new RecordFilterDescriptor("state_N"); filter.Expression = "[State] LIKE ''N*''"; this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(filter); Here is a sample.


DA David March 15, 2004 09:58 PM UTC

Okay. Given this, is there a way to filter out a particular set, as in "[State] Not ''''NY''''"? Thanks!


AD Administrator Syncfusion Team March 16, 2004 09:42 AM UTC

Currently, there is no NOT operator. But logical expressions return truth values of 1 or 0. So, if you want any state that does not begin with ''N'', then you can use something like: filter.Expression = "([State] LIKE ''N*'') = 0"; Or, equivalently, filter.Expression = "1 - ([State] LIKE ''N*'')";


DA David April 5, 2004 02:10 AM UTC

After applying a filter, I have tried to remove it, but the grid does not reset. How should I modify the grid to reset. The following is my code: if(!this.verboseOff) { RecordFilterDescriptor filter = new RecordFilterDescriptor("Verbose"); filter.Expression = "([Level] Like ''Error'') = 0"; this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(filter); this.verboseOff = true; } else { this.gridGroupingControl1.TableDescriptor.RecordFilters.Remove("Verbose"); this.verboseOff = false; this.gridGroupingControl1.Update(); }


AD Administrator Syncfusion Team April 5, 2004 10:32 AM UTC

That''s odd. Your code looks correct and should correctly reset the records. I also checked with our GroupCustomers sample and modified it to check if there is a problem in our code base with handling the code snippets you posted but it worked fine. If for some reason you need to manually reset the grid you can set groupingGrid.Table.TableDirty = true and then call groupingGrid.Refresh() Stefan >After applying a filter, I have tried to remove it, but the grid does not reset. How should I modify the grid to reset. The following is my code: > > if(!this.verboseOff) > { > RecordFilterDescriptor filter = new RecordFilterDescriptor("Verbose"); > filter.Expression = "([Level] Like ''Error'') = 0"; > this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(filter); > this.verboseOff = true; > } > > else { > this.gridGroupingControl1.TableDescriptor.RecordFilters.Remove("Verbose"); > this.verboseOff = false; > this.gridGroupingControl1.Update(); > }


DA David April 12, 2004 07:46 PM UTC

Can you provide me with an example using the GroupingGridControl bound to a DataTable, where you can enable and disable a filter for which results to show? I may have some trivial code wrong and a working example would help tremendously. Thanks, David


AD Administrator Syncfusion Team April 13, 2004 09:50 AM UTC

There does appear to be a problem here with the Filter collection. It looks like the collection is using the expression as the look up value instead of the name. So, when you try to find the filter using the name, it cannot. So, you cannot remove it. So, as a work around until we get this corrected (correction should be in the final release), you can use the expression value as the lookup key. Here is the above sample modified showing things working using the expression as the lookup. GroupingDataSample_4766.zip


DA David April 14, 2004 08:08 PM UTC

Thanks. One more thing... In order to let a client chose how to filter, I need to come up with a list of unique items in a column. I can take the list from either the DataTable or the GridGroupingControl. Do you have any suggestions? Thanks! David >There does appear to be a problem here with the Filter collection. It looks like the collection is using the expression as the look up value instead of the name. So, when you try to find the filter using the name, it cannot. So, you cannot remove it. > >So, as a work around until we get this corrected (correction should be in the final release), you can use the expression value as the lookup key. Here is the above sample modified showing things working using the expression as the lookup. >GroupingDataSample_4766.zip > >


AD Administrator Syncfusion Team April 14, 2004 08:45 PM UTC

I would probably get it from the DataTable. If you have our source, there is a method GridFilterBar.CreateUniqueEntries that does this for our Filterbar.

Loader.
Live Chat Icon For mobile
Up arrow icon