filter on the combobox itemssource
You can achieve this requirement by setting GridTemplateColumn.DisplayBinding with convert the value to be displayed and GridTemplateColumn.UseBindingValue to true to load display binding values. Find the sample and code snippets below,
Sample:
http://www.syncfusion.com/downloads/support/forum/121745/ze/WpfTestingSample-1778893011
|
<Syncfusion:GridTemplateColumn MappingName="CountryCode" UseBindingValue="True"> <Syncfusion:GridTemplateColumn.DisplayBinding> <Binding Path="CountryCode"> <Binding.Converter> <local:DisplayMemberConverter DisplayMemberPath="CountryName" SelectedValuePath="CountryCode" DataContext="{StaticResource viewmodel}"/> </Binding.Converter> </Binding> </Syncfusion:GridTemplateColumn.DisplayBinding> <Syncfusion:GridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox x:Name="combobox" ItemsSource="{Binding Companies,Source={StaticResource viewmodel}}" SelectedValue="{Binding Path=CountryCode}" DisplayMemberPath="CountryName" SelectedValuePath="CountryCode" /> </DataTemplate> </Syncfusion:GridTemplateColumn.CellTemplate> |
Converter class
|
public class DisplayMemberConverter : IValueConverter { public string DisplayMemberPath { get; set; } public string SelectedValuePath { get; set; } public object DataContext { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var selectedValue = value; IEnumerable list = null; var displayMemberPath = DisplayMemberPath; var valueMemberPath = SelectedValuePath;
list = (DataContext as ViewModel).Companies; if (selectedValue == null) return null;
PropertyDescriptorCollection pdc = null;
if (string.IsNullOrEmpty(valueMemberPath)) { if (!string.IsNullOrEmpty(displayMemberPath)) { var type = selectedValue.GetType();
pdc = TypeDescriptor.GetProperties(type);
return pdc.GetValue(selectedValue, displayMemberPath); } return selectedValue; } else { if (list == null) return null;
var enumerator = list.GetEnumerator(); while (enumerator.MoveNext()) { var type = enumerator.Current.GetType(); pdc = pdc ?? TypeDescriptor.GetProperties(type);
if (selectedValue.Equals(pdc.GetValue(enumerator.Current, valueMemberPath))) { if (!string.IsNullOrEmpty(displayMemberPath)) return pdc.GetValue(enumerator.Current, displayMemberPath); return enumerator.Current; } } } return null; }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; }
|
Thanks,
Sivakumar
- in the same example, i'm using the option ShowGroupDropArea="True". With the textcolumns is ok, while in the gridtemplatecolumn the grouping works but the value displayed are the "selectedvalue" while again i would like to show the displaymemberpath.
- in the gridtemplatecolum the sorting works on the selectedvalue, while i would like it work on displaymeberpath. Is it possible?
We have prepared a sample as per your requirement and you download the sample from the below location, In SfDataGrid by default, the GroupCaption text is displayed in the {ColumnName}: {Key} – {ItemsCount} format. You can customize the GroupCaptionText by customizing the GridCaptionSummaryCellRenderer class and you can use the sortcomparer for achieve the customize sorting requirement,
Sample : http://www.syncfusion.com/downloads/support/forum/121745/ze/WpfTestingSample472262859
You can also refer the below KB for customize the CaptionSummaryCell text
https://www.syncfusion.com/kb/3249/how-to-customize-the-captionsummarycell-text-in-the-sfdatagrid
Please the below UG for know more about sort comparer
http://help.syncfusion.com/wpf/sfdatagrid/sorting#custom-sorting
Regards,
Sowndaiyan
Attachment: samples_1e03b735.zip
We could not get your requirement clearly. Please find the modified sample where sorting, filtering and grouping works based on display value.
|
<Syncfusion:GridTemplateColumn MappingName="CountryCode" UseBindingValue="True"> <Syncfusion:GridTemplateColumn.ValueBinding> <Binding Path="CountryCode"> <Binding.Converter> <local:DisplayMemberConverter DisplayMemberPath="CountryName" SelectedValuePath="CountryCode" DataContext="{StaticResource viewmodel}"/> </Binding.Converter> </Binding> </Syncfusion:GridTemplateColumn.ValueBinding> <Syncfusion:GridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox x:Name="combobox" ItemsSource="{Binding Companies,Source={StaticResource viewmodel}}" SelectedValue="{Binding Path=CountryCode}" DisplayMemberPath="CountryName" SelectedValuePath="CountryCode" /> </DataTemplate> </Syncfusion:GridTemplateColumn.CellTemplate> |
Sample:
http://www.syncfusion.com/downloads/support/directtrac/general/ze/WpfTestingSample-1640837721.zip
Refer below KB and modify renderer based on your requirement, If you want, group header to display based on MappingName.
https://www.syncfusion.com/kb/3249/
Thanks,
Sivakumar
Attachment: SampleExplanation_57ab41f3.zip
We have analyzed your document, where you have using the same MappingName “Aziend” for two columns. In SfDataGrid, the Sorting, Grouping, Filtering operations are performed in each column based on MappingName. Hence the columns is not Sorted as expected, so we are recommended you to use the unique mapping name for each column to achieve your requirement.
Regards,
Farjana Parveen A
Currently, we are checking the reported sorting problem with DataTable Collection. We will update the details by Feb 16th, 2016.
Thanks,
Jayapradha
SfDataGrid does not support CustomSorting with DataTable collection. Since sorting and filtering will be done in DataTable itself. But you can converts the DataTable to Dynamic Object and make use of CustomSorting.
We have prepared a sample for your reference and find the sample from the following location,
Sample Link: http://www.syncfusion.com/downloads/support/forum/121745/ze/SfDataGridSample1714503220
Please find the stack overflow link to convert the DataTable to Dynamic object,
Reference Link: http://stackoverflow.com/questions/7794818/how-can-i-convert-a-datatable-into-a-dynamic-object
Regards,
Jayapradha
| Contacts | ||
| idCon | Name | idCustomer |
| 1 | Marco Del Frate | 1 |
| 2 | Daniele Amato | 1 |
| 3 | Luciano Basteri | 1 |
| 4 | Giuseppe Benelli | 2 |
| Customer | |
| idCust | Name |
| 1 | Microsoft |
| 2 | Apple |
| Name | Customer |
| Marco Del Frate | Microsoft |
| Daniele Amato | Microsoft |
| Luciano Basteri | Microsoft |
| Giuseppe Benelli | Apple |
Please find the sample where we have converted DataTable to dynamic before binding to SfDataGrid to achieve your requirement.
this.EmployeeCollection = DataTableExtensions.ToDynamic(this.DTSource);
Sample:
http://www.syncfusion.com/downloads/support/forum/121745/ze/DataTableSample-2017615816
Thanks,
Sivakumar
- 12 Replies
- 5 Participants
-
MD marco del frate
- Jan 21, 2016 11:24 AM UTC
- Mar 8, 2016 04:27 PM UTC