- Home
- Forum
- Xamarin.Forms
- Example of displaying datetime and edit data types directly on SfDataGrid
Example of displaying datetime and edit data types directly on SfDataGrid
Hello, I would be pleased to provide an example of datetime data type handling on SfDataGrid. Direct display and editing.
Many thanks.
SIGN IN To post a reply.
7 Replies
1 reply marked as answer
SS
Sivaraman Sivagurunathan
Syncfusion Team
October 9, 2020 05:56 AM UTC
Hi SHN,
Thanks for the update.
We have checked your query. you can load the date time data type and you can edit that column using GridDateTimeColumn. To edit the DataGrid we need to set AllowEditing as True, NavigationMode as Cell and enable the SelectionMode. Please refer the following code snippet. And we have pared the sample for your reference you can download the same from the below link.
|
<sfDataGrid:SfDataGrid x:Name="sfDataGrid"
AllowEditing="True"
SelectionMode="Single"
NavigationMode="Cell"
ItemsSource="{Binding OrdersInfo}"
ColumnSizer="None"
AutoGenerateColumns="True">
<sfDataGrid:SfDataGrid.Columns>
<sfDataGrid:GridTextColumn MappingName="OrderID" />
<sfDataGrid:GridTextColumn MappingName="EmployeeID" />
<sfDataGrid:GridTextColumn MappingName="CustomerID" />
<sfDataGrid:GridDateTimeColumn MappingName="ShippingDate"/>
</sfDataGrid:SfDataGrid.Columns>
</sfDataGrid:SfDataGrid>
|
Sample Link: https://www.syncfusion.com/downloads/support/forum/158511/ze/DataGridSample_(18)-39167470
Regards,
Sivaraman S
Marked as answer
SH
SHN
October 12, 2020 01:48 AM UTC
Many thanks for your demo.Sivaraman S . In case I do encounter it.
Datetime data is very diverse.
Such as :
+ "1900/01/01 18:00:00".
-> The format in the format: "hh: mm: ss" will be "18:00:00".
+ "2020/10/12 18:00:00"
-> The format in "dd / mm / yyyy" format will be "12/10/2020".
+ If datetime is null, it will take the default format "dd / mm / yyyy". Value is the current date.
I noticed that GridDateTimeColumn can only edit date data. What if I want to edit the time?
Do not know if you can handle any of the above specific cases? We look forward to your answer. Thank you very much.
SS
Sivaraman Sivagurunathan
Syncfusion Team
October 12, 2020 09:03 AM UTC
Hi SHN
Thanks for your update.
We have checked your query. we have load the Xamarin.Forms.DatePicker in GridDateTimeColumn, So we cannot edit the time value in GridDateTimeColumn. And we can set the Format for the GridDateTimeColumn based on your requirement. Please refer the following code snippet for your reference also we have modified the sample. You can download the same from the below link.
|
<sfgrid:SfDataGrid.Columns>
<sfgrid:GridDateTimeColumn Format="d"
HeaderText="Shipped Date"
MappingName="ShippingDate" />
</sfgrid:SfDataGrid.Columns>
|
Regards,
Sivaraman S
SH
SHN
October 14, 2020 02:03 AM UTC
Hello,Sivaraman S .
I am quite sorry that a data type as brave as time cannot be edited in the grid.
I have tried to refine my data editing with external built-in fields.
As I mentioned in the picture, I have 3 parts.
Controls, Searchbar, SfDataGrid.
Use a datatable to bind data to controls, and use that same table as the ItemSource for the SfDatagrid.
I use the datatable's DefaultView.RowFilter to filter.
As of now, I gain, when editing on controls. The data in SfDataGrid will change as well.
However. When I started to filter. I'll just get the matching lines. When I do, I want the first line in my filter result to be bound to the controls. Is there any way to achieve this wish?
We look forward to hearing from you.
SS
Sivaraman Sivagurunathan
Syncfusion Team
October 14, 2020 10:49 AM UTC
Hi SHN,
Thanks for your update.
We have checked your query. you can get the first row record using GetCellValue and GetRecordAtRowIndex methods when filter the record. Please find the following code snippet. We have prepared the sample for your requirement and attached for your reference. You can download the same from the below link.
|
public partial class MainPage : ContentPage
{
DataView view;
public MainPage()
{
InitializeComponent();
dataGrid.CanUseViewFilter = true;
view = new DataView();
ViewModel.Records.TableName = "DT";
view.Table = ViewModel.Records;
dataGrid.ItemsSource = view;
}
public void RaiseCollectionChanged(string propName)
{
if (this.CollectionChanged != null)
this.CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public event NotifyCollectionChangedEventHandler CollectionChanged;
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
view.RowFilter = "Column2 >= '" + e.NewTextValue + "'";
label.Text = dataGrid.GetCellValue(dataGrid.GetRecordAtRowIndex(1), "Column2").ToString();
}
}
|
Regards,
Sivaraman S
SH
SHN
October 27, 2020 03:23 AM UTC
Hi Sivaraman Sivagurunathan, thank you for update. I will try <3
SS
Sivaraman Sivagurunathan
Syncfusion Team
October 27, 2020 04:44 AM UTC
Hi SHN,
Thanks for your update. We will wait to hear from you.
Regards,
Sivaraman S
SIGN IN To post a reply.