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.
Unfortunately, activation email could not send to your email. Please try again.

Create a custom filter to display the Top N of a datatable only

Thread ID:

Created:

Updated:

Platform:

Replies:

124749 Jun 27,2016 02:25 PM Jun 30,2016 02:57 AM Windows Forms 5
loading
Tags: GridGroupingControl
Steven Paplanus
Asked On June 27, 2016 02:25 PM

I have an application where I wish to be able to allow the user to filter the records by being in the Top 10 (though it could reasonably be any Top number amount), on the specified filtered column.   I know I can do this manually by creating my own custom datatable that displays it, but even if that is the only recourse, I would at least like to be able to put that custom choice in the filter dialog.  Any suggestions would be appreciated.

Steve

Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 28, 2016 07:54 AM

Hi Steven, 

Thank you using Syncfusion products. 

As per your scenario, it seems that you are using dynamic filter or normal filter in your application. 
The Top10 numbers filtering for the column feature is not available in both the filters. But Top 10 number filtering is available in the advanced filtering which is GridExcelFilter. By using GridExcelFilter , you can filter the top 10 values of a numbered column. So we would like to suggest to use the GridExcelFilter. Please make use of below code. 

Code snippet 
//Form() 
GridExcelFilter excelfilter = new GridExcelFilter(); 
excelfilter.WireGrid(this.gridGroupingControl1); 
//To enable the NumberFilter. 
excelfilter.EnableNumberFilter = true; 
 
 
 
 
 
 
Note: 
If you want to enable NumberFilter, that column should be an NumberColumn (i.e integer column , decimal column..etc). 
 
Sample link 
 
Dashboard sample link 
<Installed Location>\Syncfusion\EssentialStudio\<VersionNumber>\Windows\Grid.Grouping.Windows\Samples\Filters and Expressions\Optimized Excel Filter Demo 
 
Regards, 
Piruthiviraj 


Steven Paplanus
Replied On June 28, 2016 03:40 PM

Thank you very much, this helped.  I do have one issue, which is that I can't seem to retrieve from the filtered table the filtered records, as I did by using the gridGroupingControl1.Table.FilteredRecords property.   Is there any way to retrieve the filter records from the GridExcelFilter?

Steve

Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 29, 2016 07:11 AM

Hi Steven, 

Thank you for your update. 

We have analyzed and tested your reported scenario at our end. The filtered records can be get using the FilteredRecords property. Here we have provided the sample which shows the getting of filtered records. Can you check the below sample and below code snippet? Please let us know if we missed anything. 
 
Code snippet 
 
private void button1_Click(object sender, EventArgs e) 
{ 
    FilteredRecordsInTableCollection filteredRecords = this.gridGroupingControl1.Table.FilteredRecords; 
    MessageBox.Show("FilteredReocords count:" + filteredRecords.Count.ToString()); 
} 

 


Sample link 


Regards, 
Piruthiviraj 


Steven Paplanus
Replied On June 29, 2016 10:29 AM

I think the issue is that I am trying to find an event that gives me the correct filtered rows.  It is true that if I have a separate button that queries the filtered count after the user selects a "Top 10" filter, that it returns the correct value.  However, the problem is that I haven't found an event that occurs that gives me the correct item in response to the changing of the filtered records.  I tried the RecordFiltersItemChanged event (as well as RecordFiltersItemChanging) on the gridexcelfilter and I have tried going against the DisplayElementChanged and FilterBarSelectedItemChanged against the grid itself, but it returns the count before the filter.  I have modified the datatable sample project with the code, so that you can see what I see.   I need to be able to grab the right items when the user changes the filter (in this case the Top N by left clicking on the filter icon on the column (in this case the description column). 

Attachment: DataGrid_15637db8.zip

Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 30, 2016 02:57 AM

Hi Steven, 

Thanks for your update. 

The filtered records (using Top 10 filter) can be retrieved by using RecordFilters.Changed event of GridTableDescriptor. Please make use of the below code. 
 
Code snippet 
 
this.gridGroupingControl1.TableDescriptor.RecordFilters.Changed += new Syncfusion.Collections.ListPropertyChangedEventHandler(RecordFilters_Changed); 
 
void RecordFilters_Changed(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e) 
    if ((e.Action == Syncfusion.Collections.ListPropertyChangedType.Add || e.Action == Syncfusion.Collections.ListPropertyChangedType.ItemChanged) && e.Item != null
    { 
        FilteredRecordsInTableCollection filteredRecords = this.gridGroupingControl1.Table.FilteredRecords; 
        MessageBox.Show("FilteredReocords count:" + filteredRecords.Count.ToString()); 
    } 
 
Sample link 
 
Regards, 
Piruthiviraj 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;