Skip to content

Commit ff8f913

Browse files
Merge pull request #3530 from syncfusion-content/968735
Added UG content and Images for the PickerColumn Feature in MAUI DataGrid
2 parents f6e02d5 + d3c146f commit ff8f913

File tree

6 files changed

+180
-3
lines changed

6 files changed

+180
-3
lines changed

MAUI/DataGrid/Column-types.md

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ The following table describes the types of columns and their usage:
6565
<td>{{'[DataGridComboBoxColumn](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridComboBoxColumn.html)'| markdownify }}</td>
6666
<td>{{'[DataGridComboBoxRenderer](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridComboBoxRenderer.html)'| markdownify }}</td>
6767
<td>ComboBox</td>
68-
<td>To display the date and time value.</td>
68+
<td>To display a ComboBox within each cell</td>
69+
</tr>
70+
<tr>
71+
<td>{{`DataGridPickerColumn`| markdownify }}</td>
72+
<td>{{'[DataGridPickerCellRenderer]'| markdownify }}</td>
73+
<td>Picker</td>
74+
<td>To display a Picker within each cell</td>
6975
</tr>
7076
<tr>
7177
<td>{{'[DataGridUnboundColumn](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridUnboundColumn.html)'| markdownify }}</td>
@@ -1012,6 +1018,177 @@ The [DataGridComboBoxColumn.CanFilterSuggestions](https://help.syncfusion.com/cr
10121018
{% endhighlight %}
10131019
{% endtabs %}
10141020

1021+
## DataGridPickerColumn
1022+
1023+
The `DataGridPickerColumn` inherits all the properties of the [SfDataGrid.DataGridColumn](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridColumn.html). It displays a list of items in the form of a [SfPicker](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Picker.SfPicker.html) as the content of a column. To enable or disable editing for a particular column, set the [DataGridColumn.AllowEditing](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridColumn.html#Syncfusion_Maui_DataGrid_DataGridColumn_AllowEditing) property to true or false. When in editing mode, it displays a `SfPicker` element. The data source for the `SfPicker` can be set using the `DataGridPickerColumn.ItemsSource` property. The picker column can be populated with data in the following ways:
1024+
1025+
* Collection of primitive types
1026+
* Collection of user-defined types (custom objects)
1027+
1028+
![DataGrid with editing in picker column](Images\column-types\maui-datagrid-picker-column.png)
1029+
1030+
### Collection of primitive types
1031+
1032+
To display the collection of items in the Picker drop-down, create a `DataGridPickerColumn` and set its `ItemsSource` property to a simple collection.
1033+
1034+
To load the `DataGridPickerColumn` with a simple string collection, you can refer to the code example below:
1035+
1036+
{% tabs %}
1037+
{% highlight xaml %}
1038+
<ContentPage.BindingContext>
1039+
<local:ViewModel x:Name="viewModel" />
1040+
</ContentPage.BindingContext>
1041+
1042+
<sfGrid:SfDataGrid x:Name="dataGrid"
1043+
ItemsSource="{Binding DealerInformation}"
1044+
AllowEditing="True">
1045+
<sfGrid:SfDataGrid.Columns>
1046+
<sfgrid:DataGridPickerColumn HeaderText="Ship Country"
1047+
MappingName="ShipCountry"
1048+
ItemsSource="{Binding Countries}"/>
1049+
</sfGrid:SfDataGrid.Columns>
1050+
</sfGrid:SfDataGrid>
1051+
{% endhighlight %}
1052+
1053+
{% highlight c# %}
1054+
SfDataGrid dataGrid = new SfDataGrid();
1055+
dataGrid.ItemsSource = viewModel.DealerInformation;
1056+
dataGrid.AllowEditing = true;
1057+
DataGridPickerColumn pickerColumn = new DataGridPickerColumn()
1058+
{
1059+
MappingName = "ShipCountry",
1060+
HeaderText = "Ship Country",
1061+
ItemsSource = viewModel.Countries
1062+
};
1063+
dataGrid.Columns.Add(pickerColumn);
1064+
{% endhighlight %}
1065+
{% endtabs %}
1066+
1067+
{% tabs %}
1068+
{% highlight c# %}
1069+
1070+
public class ViewModel
1071+
{
1072+
public ObservableCollection<DealerInfo> DealerInformation { get; set; }
1073+
public ObservableCollection<string> Countries { get; set; }
1074+
1075+
public ViewModel()
1076+
{
1077+
this.Countries = this.shipCountry.ToObservableCollection();
1078+
}
1079+
1080+
private string[] shipCountry = new string[]
1081+
{
1082+
"Argentina",
1083+
"Austria",
1084+
"Belgium",
1085+
"Brazil",
1086+
"Canada",
1087+
"Denmark",
1088+
"Finland",
1089+
"France",
1090+
"Germany",
1091+
"Ireland",
1092+
"Italy",
1093+
"Mexico",
1094+
"Norway",
1095+
"Poland",
1096+
"Portugal",
1097+
"Spain",
1098+
"Sweden",
1099+
"UK",
1100+
"USA",
1101+
};
1102+
}
1103+
{% endhighlight %}
1104+
{% endtabs %}
1105+
1106+
### Collection of user-defined types
1107+
1108+
To display a list of user-defined items in the picker, create a `DataGridPickerColumn` and set its `ItemsSource` property to a user-defined collection. By default, if the `DisplayMemberPath` is not set, the picker column will display the values from the `MappingName` property of the column.
1109+
1110+
#### Display member path
1111+
1112+
Displays a value by comparing values of the properties set as `DataGridColumn.MappingName` and `ValueMemberPath` in their respective underlying collections. If the values of `ValueMemberPath` property contains the current value of `MappingName` property, its corresponding value of `DisplayMemberPath` property is displayed in the `DataGridCell`. Or else the `DataGridCell` appears blank. However, in edit mode the values of the `DisplayMemberPath` property are displayed as picker items.
1113+
1114+
#### Value member path
1115+
1116+
Once editing completed, the column having the `MappingName` equal to the `ValueMemberPath` has its data changed to the corresponding `ValueMemberPath` value for the selected `DisplayMemberPath` value in the picker.
1117+
1118+
### Loading different ItemSource for each row of DataGridPickerColumn
1119+
1120+
To load different ItemSources for each row of a DataGridPickerColumn, you can utilize the `DataGridPickerColumn.ItemsSourceSelector` property.
1121+
1122+
### Implementing IItemsSourceSelector
1123+
1124+
`DataGridPickerColumn.ItemsSourceSelector` needs to implement the IItemsSourceSelector interface, which requires you to implement the GetItemsSource method. This method receives the following parameters:
1125+
1126+
* Record: This is the data object associated with the row.
1127+
* Data Context: This is the binding context of the data grid.
1128+
1129+
In the provided code, the ItemsSource for the ShipCity column is returned based on the value of the ShipCountry column. This is done by using the record and the binding context of the data grid, which are passed to the GetItemsSource method.
1130+
1131+
{% tabs %}
1132+
{% highlight xaml %}
1133+
<ContentPage.Resources>
1134+
<ResourceDictionary>
1135+
<local:ItemSourceSelector x:Key="converter" />
1136+
</ResourceDictionary>
1137+
</ContentPage.Resources>
1138+
1139+
<sfgrid:SfDataGrid x:Name="dataGrid"
1140+
ItemsSource="{Binding DealerInformation}"
1141+
AllowEditing="True"
1142+
AutoGenerateColumnsMode="None"
1143+
NavigationMode="Cell"
1144+
EditTapAction="OnDoubleTap"
1145+
SelectionMode="Single">
1146+
<sfgrid:SfDataGrid.Columns>
1147+
<sfgrid:DataGridPickerColumn BindingContext="{x:Reference viewModel}"
1148+
ItemsSource="{Binding CountryList}"
1149+
MappingName="ShipCountry"
1150+
LoadUIView="True">
1151+
</sfgrid:DataGridPickerColumn>
1152+
1153+
<sfgrid:DataGridPickerColumn ItemsSourceSelector="{StaticResource converter}"
1154+
MappingName="ShipCity"
1155+
LoadUIView="True">
1156+
</sfgrid:DataGridPickerColumn>
1157+
</sfgrid:SfDataGrid.Columns>
1158+
</sfgrid:SfDataGrid>
1159+
{% endhighlight %}
1160+
1161+
{% highlight c# %}
1162+
public class ItemSourceSelector : IItemsSourceSelector
1163+
{
1164+
public IEnumerable GetItemsSource(object record, object dataContext)
1165+
{
1166+
if (record == null)
1167+
{
1168+
return null;
1169+
}
1170+
1171+
var orderinfo = record as DealerInfo;
1172+
var countryName = orderinfo.ShipCountry;
1173+
var viewModel = dataContext as EditingViewModel;
1174+
1175+
// Returns ShipCity collection based on ShipCountry.
1176+
if (viewModel.ShipCities.ContainsKey(countryName))
1177+
{
1178+
string[] shipcities = null;
1179+
viewModel.ShipCities.TryGetValue(countryName, out shipcities);
1180+
return shipcities.ToList();
1181+
}
1182+
1183+
return null;
1184+
}
1185+
}
1186+
{% endhighlight %}
1187+
{% endtabs %}
1188+
1189+
![DataGrid with ItemSourceSelector picker column](Images\column-types\maui-datagrid-picker-column-itemsourceselector.png)
1190+
![DataGrid with ItemSourceSelector picker column](Images\column-types\maui-datagrid-picker-column-itemsourceselector2.png)
1191+
10151192
## DataGridNumericColumn
10161193

10171194
The `DataGridNumericColumn` inherits all the properties of the `DataGridColumn`. It is used to display numeric data. To create a `DataGridNumericColumn`, the property corresponding to the column in the underlying collection must be a numeric type (int, double, float, etc.).
45.7 KB
Loading
50 KB
Loading
44.8 KB
Loading

MAUI/DataGrid/grid-events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ private static void ListenExitedCommand(object obj)
348348

349349
## CellValueChanged event
350350

351-
The [SfDataGrid.CellValueChanged](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.SfDataGrid.html) event will be triggered whenever the current cell's value has been changed in the DataGridTextColumn, DataGridNumericColumn, DataGridDateColumn, DataGridComboBoxColumn or DataGridCheckBoxColumn. This event handler contains the parameter of type [DataGridCellValueChangedEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridCellValueChangedEventArgs.html) that contains the following properties.
351+
The [SfDataGrid.CellValueChanged](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.SfDataGrid.html) event will be triggered whenever the current cell's value has been changed in the DataGridTextColumn, DataGridNumericColumn, DataGridDateColumn, DataGridComboBoxColumn, DataGridPickerColumn or DataGridCheckBoxColumn. This event handler contains the parameter of type [DataGridCellValueChangedEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridCellValueChangedEventArgs.html) that contains the following properties.
352352

353353
* [Column](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridCellValueChangedEventArgs.html#Syncfusion_Maui_DataGrid_DataGridCellValueChangedEventArgs_Column) : Gets the current `DataGridColumn` that contains the grid cell for which value is edited or changed.
354354
* [NewValue](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridCellValueChangedEventArgs.html#Syncfusion_Maui_DataGrid_DataGridCellValueChangedEventArgs_NewValue) : The newly edited value to be committed.

MAUI/DataGrid/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The .NET MAUI DataGrid control is used to display and manipulate data in a tabul
1818

1919
* **Data Binding** - Bind different types of data sources, including DataTable.
2020

21-
* **Column Types** - Show different data types in different types of columns. The following column types are supported: numeric, text, date, checkbox, image, combobox and template. The template column is used to load any control in a column.
21+
* **Column Types** - Show different data types in different types of columns. The following column types are supported: numeric, text, date, checkbox, image, combobox, picker and template. The template column is used to load any control in a column.
2222

2323
* **Column Resizing** - Interactive support to adjust the width of columns.
2424

0 commit comments

Comments
 (0)