This is a migrated thread and some comments may be shown as answers.

Find functiontionality in RadPivotGrid

5 Answers 87 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 26 Dec 2014, 11:02 AM
Hello Telerik team!

I need your help. 
I would like to implement search functionality in RadPivotGrid like in Excel. There should be TextBox and button "Find". When user presses button, he gets rows which contains the string. I tryed the following:

1. Using pivot's filters. There was no success, because I can't create filter which has multi column condition. This mechanism can filter data only for specific column. And I need to search in all columns.

2. Search using DataProvider. I can get access to data using DataProvider, but I can't relate this data with visual elements. Example of code:

            IPivotResults results = _pivot.DataProvider.Results;
            var searchText = SearchTextBox.Text;

            foreach (IGroup rowGroup in results.Root.RowGroup.Groups)
            {
                foreach (IGroup columnGroup in results.Root.ColumnGroup.Groups)
                {
                    var aValue = results.GetAggregateResult(0, rowGroup, columnGroup);
                    if (aValue != null && aValue.ToString().Contains(searchText))
                    {
                        //TODO: Mark result here
                    }
                }
            }

So, I'm not able to mark the results of search.

3. Search using TextBlocks and DataTemplate. I implemented DataTemplate which contains TextBlocks with attachable property. This property marks TextBlock and add it to special list. Then, when user presses search button I look in this list of TextBlocks which contain the string. There are two problems with it: I can't do navigation to results, and I need to switch off virtualization because I will not be able to search in elements, which is not in visual tree. Example:

 <DataTemplate>
                    <Grid Name="CellGrid">
                        <TextBlock Text="{Binding Data, Mode=OneWay}" VerticalAlignment="Center" HorizontalAlignment="Right"
                                   Margin="2,1" SearchService.SearchArea="PivotSearch" />
                    </Grid>
                </DataTemplate>


        public static void Search(string searchArea, string searchText)
        {
            var list = SearchService.GetTextBlockList(searchArea);
            var foundTextBlocks = list.Where(x => x.Text.Contains(searchText);
            
            //TODO: naviagate to result in scroll case
        }

I will be appreciated for any help. Thank you.






5 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 30 Dec 2014, 03:21 PM
Hi Alexander,

Could you please provide us some more detailed information about the exact functionality you'd like to achieve? For example as soon as a cell is found what exact information you'd expect to be visualized for that cell. Do you need to filter the PivotGrid anyhow? Any provided additional information will be of great help for us to better understand your scenario and provide you with a solution if possible.

We are looking forward to hearing from you.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alexander
Top achievements
Rank 1
answered on 13 Jan 2015, 09:43 AM
Hello Nasko,

Thank you for the response.

Ideally I would like to achieve the following functionality: when user types string for searching, system performs search and marks results of searching in all cells in pivot. For example user types 'D' and all cells which contain D should me marked by yellow color. Then user presses button "Search" and the first cell which contains the searching string must be marked by red color. Then user presses "Search" again and the next cell which contains searching result must be marked by red color, and previous cell should become unmarked. Pivot can contain scroll - that's why some of my implementations are not correct.

The minimum functionality is the following: user types string for searching, presses search button, and the first cell which contains searching result become marked (for example marked by color of cell's background). Than user presses search button again and the next cell which contains searching string become marked and the previous one become unmarked.

Filtering functionality is not necessary but if it can be implemented it would be fine.

I would be appreciate for any similar suggestion of search functionality which can be implemented in Pivot.
Thank you!
0
Nasko
Telerik team
answered on 16 Jan 2015, 02:21 PM
Hello Alexander,

What we could suggest suggest you in order to achieve the desired is to use Custom CellTemplateSelector - based on the text entered inside the TextBox the cells should apply different template. The text could be passed to the CellTemplateSelector using the TextChanged event. The same logic is also valid when the "Search" button is pressed - a new template should be applied to the first cell that matches the searched text. More detailed information about the CellTemplateSelector you could find on the following article from out help documentation and that sample project from out SDK repository:
http://docs.telerik.com/devtools/wpf/controls/radpivotgrid/styles-and-templates/templating-cells.html#using-custom-celltemplateselector

We have created a sample project that demonstrates the described above approach. Please, give it a try and let us know if it worked for you.

Hopes this helps.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alexander
Top achievements
Rank 1
answered on 19 Jan 2015, 11:29 AM
Hello Nasko,

Thanks for the example – it’s very helpful. However I have several questions and notes.

1. Example that you provided cannot perform search in column headers and row headers. Is it possible?
2. If I click on button, one cell becomes selected. But if I’ll click second time, cell remains selected and I would like to unselect that cell and select the next cell which contains searchable string.
3. If I’ll scroll out of the cell and then scroll back to the screen with selected cell, it becomes unselected (I mean selection which was performed by pressing button).
4. If the cell out of the screen I will not see that cell is selected when I’ll press search button. I would like to scroll to the cell with the search result.

Thank you for response, hope we’ll solve this issue.

0
Nasko
Telerik team
answered on 22 Jan 2015, 09:55 AM
Hello Alexander,

Note that the sample project we sent doesn't provide the complete desired functionality, but it demonstrates an approach that could be used to achieve it - thus you could modify it to suit your needs and requirements. 
  • In order to implement a search functionality for the rows and columns headers you need to create a custom RowHeaderTemplate and ColumnHeaderTemplate that should be applied when a column or row header matches the search requirements. Please, check the following article from out help documentation that provides more detailed information for both Templates: http://docs.telerik.com/devtools/silverlight/controls/radpivotgrid/styles-and-templates/templating-cells#using-custom-cell-and-header-templates
  • In the sample project we just want to demonstrate how a different template is applied to a cell that meets some requirements - just the first cell applied it. Inside the SelectTemplate method you should implement your own logic based on which every time the "Search" button is pressed a new cell should apply some custom template.
  • That behavior is caused because the "ShouldSelectCell" method that is inside "CellTemplateSelector" - the values should be converted to double before comparing them. The following code snippet demonstrates how to avoid this:

var cellValue = Convert.ToDouble(cellAggregate.Value);
var selectedCellvalue = Convert.ToDouble(this.SelectedCell.Value);
  
if (selectedCellvalue == cellValue)
{
    return true;
}

 

  • RadPivotGrid generates for visualization only the cells that are visible in the screen. The solution that we suggested will only work for the cells that are currently visible and generated.

We hope the provided information is helpful.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
PivotGrid
Asked by
Alexander
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or