How to autocomplete datatime cell
In GGC, I have cell with type is DateTime. I want when I type date value and leave, GGC auto fill month and year value, i.e type 10 and result 10/04/2017. How can I do this ?
Thanks
Thanks
SIGN IN To post a reply.
3 Replies
PM
Piruthiviraj Malaimelraj
Syncfusion Team
April 11, 2017 11:28 AM UTC
Hi Hieudt,
Thanks for your interest in Syncfusion products.
We could able to understand your scenario. Currently the GridGroupingControl does not have the direct support to autocomplete the date values. This scenario can be achieved by creating the CustomCellType using GridDropDownMonthCalendarCellModel and GridDropDownMonthCalendarCellRenderer. Please make use of the below code.
Code example:
|
//Create CustomCellModel
class DateTimeExt1Model : GridDropDownMonthCalendarCellModel
{
public DateTimeExt1Model(GridModel grid)
: base(grid)
{
}
public override bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo)
{
string month;
string year;
DateTime isDate;
//To set the month and year of previous value.
if (style.Text != string.Empty && DateTime.TryParse(style.CellValue.ToString(),out isDate) && text.Length<=2)
{
DateTime time = (DateTime)style.CellValue;
month = time.Month.ToString();
year = time.Year.ToString();
month += "-" + text + "-" + year;
}
//To set the current month and year
else if (text.Length <= 2)
{
month = DateTime.Now.Month.ToString();
year = DateTime.Now.Year.ToString();
month += "-" + text + "-" + year;
}
else
month = text;
return base.ApplyFormattedText(style, month, textInfo);
}
public override GridCellRendererBase CreateRenderer(GridControlBase control)
{
return new DateTimeExt1Renderer(control, this);
}
}
//Adding CustomCellModel
this.gridGroupingControl1.TableModel.CellModels.Add("DateTimeExt", new DateTimeExtModel(this.gridGroupingControl1.TableModel));
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellType = "DateTimeExt";
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellValueType = typeof(DateTime);
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.Format = "dd/MM/yyyy";
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.ShowButtons = GridShowButtons.Hide; |
Sample link:
Note:
In above solution , we have provided the solution to autocomplete the date value with (current month & current year) and (also with month & year of previous value before editing). If you want to complete the date value with current month and year always, please remove the below highlighted code.
|
public override bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo)
{
string month;
string year;
DateTime isDate;
//To set the month and year of previous value.
if (style.Text != string.Empty && DateTime.TryParse(style.CellValue.ToString(),out isDate) && text.Length<=2)
{
DateTime time = (DateTime)style.CellValue;
month = time.Month.ToString();
year = time.Year.ToString();
month += "-" + text + "-" + year;
}
//To set the current month and year
else if (text.Length <= 2)
{
month = DateTime.Now.Month.ToString();
year = DateTime.Now.Year.ToString();
month += "-" + text + "-" + year;
}
else
month = text;
return base.ApplyFormattedText(style, month, textInfo);
} |
Regards,
Piruthiviraj
HI
hieudt
April 12, 2017 04:36 AM UTC
It works, thanks for your great help!
PM
Piruthiviraj Malaimelraj
Syncfusion Team
April 12, 2017 11:01 AM UTC
Hi Hieudt,
Thanks for your update.
We are glad to hear that the provided solution is resolved your scenario. Please let us know if you have any other queries.
Regards,
Piruthiviraj
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
HI hieudt
- Apr 10, 2017 08:15 AM UTC
- Apr 12, 2017 11:01 AM UTC