SfDataGrid GridDateTimeColumn : disable the calendar picker feature

Hello,

I have a large SfDataGrid containing editable cells. In order to save space (a lot of columns), I would like to hide the calendar part of the GridDateTimeColumn cell. Also We don't need it during the editing of the value.


Is it possible ? If yes, how ?

Thanks for your help


Here is a screenshot of what I need to get rid of and a template code that you can update as you wish : 

Image_4847_1691652751639


Attachment: SfGridDateTimeEdit_2e5d35dc.rar

3 Replies 1 reply marked as answer

CM Chidanand Murugaiah Syncfusion Team August 11, 2023 05:43 PM UTC

Hi Nicolas Wagener,


Your requirement will be achieved by overriding the OnEditElementLoaded event in the GridCellDateTimeRenderer class. We prepared sample for your requirement.


Please refer the below code snippet:

      public MainWindow()

      {

          InitializeComponent();

          this.dataGrid.CellRenderers.Remove("DateTime");

 

          this.dataGrid.CellRenderers.Add("DateTime", new GridCellDateTimeRenderer());

      }

  }

 

  public class GridCellDateTimeRenderer : GridVirtualizingCellRenderer<TextBlock, DateTimeEdit>

  {

      public GridCellDateTimeRenderer() { }

 

      protected override void OnEditElementLoaded(object sender, RoutedEventArgs e)

      {

          (e.Source as DateTimeEdit).IsButtonPopUpEnabled = false;

          base.OnEditElementLoaded(sender, e);

      }

  }


We hope this helps. Please let us know, if need any further assistance.


Regards,

Chidanand M.


Attachment: SfDataGrid_Demo_d1338555.zip


NW Nicolas Wagener August 16, 2023 05:23 AM UTC

Hello Chidanand,


thank you for your help, but it did not work.

See the animated screenshot : when I enter edit mode and typing the new date > it doesn't change when I leave the cell.

For the Time : same think and it show me the date when I enter edit mode.

Image_4643_1692163289374

Can you try to update the project in .net 7 version ? (not in .net framework 4.7.2 like you did before ? )


Thank you.


Nicolas


Attachment: SfGridDateTimeEdit_55883dc0.rar


CM Chidanand Murugaiah Syncfusion Team August 17, 2023 01:08 PM UTC

Hi Nicolas,


We regret for the inconvenience.


Your requirement can be achieved by overriding GridCellDateTimeRenderer instead of overriding the GridVirtualizingCellRenderer. We also modified the provided sample.

 Find the sample in the attachment.


Kindly refer the below code snippet:

     private void MainWindow_Loaded(object sender, RoutedEventArgs e)

     {

         this.DataContext = new DataViewModel();

 

         this.grid.CellRenderers.Remove("DateTime");

         this.grid.CellRenderers.Add("DateTime", new GridCellDateTimeRendererExt());

     }

}

 

public class GridCellDateTimeRendererExt : GridCellDateTimeRenderer

{

     public GridCellDateTimeRendererExt() { }

 

     protected override void OnEditElementLoaded(object sender, RoutedEventArgs e)

     {

         (e.Source as DateTimeEdit).IsButtonPopUpEnabled = false;

         base.OnEditElementLoaded(sender, e);

     }

}


We hope this helps. Please let us know, if need any further assistance.


Regards,

Chidanand M.


Attachment: SfGridDateTimeEdit_f734593d.zip

Marked as answer
Loader.
Up arrow icon