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.
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.