GridDateTimeColumn with nullable dates

Hello everybody,

I'm using SfDataGrid with three columns. There is a workflow implemented in which the user gets led through every column. After the user completed the column, the next one is focused. One of the columns is a GridDataTimeColumn so when it's automatically focused the datepicker opens. Everything fine!

However, the date is optional. In fact, the viewmodel's field is a nullable date. So if the user hits the cancel button, it would be nice to receive a null value. 

The automation is picked from an older thread, it uses sfgrid_BeginEdit to bind completion events to every column:

  private async void sfgrid_CurrentCellBeginEdit(object sender, GridCurrentCellBeginEditEventArgs args)
        {
            try
            {
                var row = sfgrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowIndex == args.RowColumnIndex.RowIndex);
                var column = (row.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "VisibleColumns").GetValue(row) as List<DataColumnBase>).FirstOrDefault(x => x.ColumnIndex == args.RowColumnIndex.ColumnIndex);
                var content = ((column as IElement).Element as ContentView).Content;

                if (content is Entry && !_entryCompletedLotAdded)
                {
                    (content as Entry).Completed += Charge_Completed;
                    _entryCompletedLotAdded = true;
                }
                else if (content is SfNumericTextBoxExt && !_entryNumericCompletedAdded)
                {           
                        (content as SfNumericTextBoxExt).Completed += Gewaehlt_Completed;
                        _entryNumericCompletedAdded = true;
                }
                else if (content is SfDatePicker && !_dateSelectedAdded)
                {
                    (content as SfDatePicker).Unfocused += Mhd_Unfocused;
                    _dateSelectedAdded = true;
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(Translator.Translate("Fehler"), ex.Message, "OK");
            }
        }

It uses SfDataPicker.Unfocused because DateSelected didn't work if the user just pressed the ok button without making any changes inside the date picker.

Hope you can help :)

2 Replies

KK Karthikraja Kalaimani Syncfusion Team April 24, 2020 02:22 PM UTC

Hi Maria,

Currently, we are validating your requirement. So, we will validate and update further details on or before 28th April 2020.

We appreciate your patience until then.

Regards,
Karthik Raja

 



KK Karthikraja Kalaimani Syncfusion Team April 28, 2020 12:06 PM UTC

Hi Maria,

Thank you for your patience.

Currently, we don’t have a support to detect the Cancel Button in GridDateTimeColumn. Since we have used Xamarin.Forms DatePicker and they have loaded the dialog in each platform renderer, and they have not exposed that dialog as public to detect the Cancel Button. So, we suggest you ditto the Xamarin Forms DatePicker code and then load custom popup instead of dialog in each platform renderer. Then load the customized DatePicker control on GridTemplateColumn to achieve your requirement.


This below links to help create custom popup.
https://stackoverflow.com/questions/55628652/xamarin-forms-picker-ok-or-cancel-button-pressed-detection

This below link to help load a custom control to GridTemplateColumn while editing.
https://help.syncfusion.com/xamarin/datagrid/column-types#edit-template


See the source code of Xamarin Forms Date Picker renderer

Android: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/Renderers/DatePickerRenderer.cs


 

Regards,
Karthik Raja
 


Loader.
Up arrow icon