I've been playing with the DataGrid for a few days now, and have a few queries/issues:
On the whole the grid feels great, by the way, very pleased with it. Just at the moment I'm a bit nervous about committing to its use in the site I'm working on. Hopefully documentation will follow shortly, and also we'll see some a quick stream of updates available via nuget?
Kevin
Hello Kevin,
I have been investigating into the questions that you have inquired about above, and I have some answers for you on this matter. I will answer your questions in the order they were asked:
1. At the moment, I do not have an ETA on when API documentation for Blazor will become available.
2. You are correct to use the DateTimeColumn’s FormatString property, but you cannot enter the format string directly. Instead, you need to use a DateTimeFormatSpecifier, and you can do this like so:
<DateTimeColumn Field="Date" FormatString="{0}"> <DateTimeFormatSpecifier Locale="en-UK" DateStyle="full"/> </DateTimeColumn>
3. At the time of writing this, there does not exist any documentation on DateTimeFormatSpecifier, but a topic about formatting columns will be written shortly.
4. I would recommend continuing to set the ColumnGroupDescriptions in C# code and ignoring the warnings that you are receiving. The warnings are coming from the Visual Studio handling of the property settings, as it “expects” it to be set in markup, but in order to add it to the grid, you need to do this in code.
I can understand this feeling, but rest assured the forums are definitely being monitored. There are not many topics likely because the Ignite UI for Blazor product is brand new at the time of writing this.
Please let me know if you have any other questions or concerns on this matter.
Hello Andrew,
Can you give me an example of how to format a date used as a grouped column in the grid. Something like this, which doesn't work:
private DataGrid GridData { get=>grdData; set { grdData = value; var dt = new ColumnGroupDescription() { Field = "Date", DisplayName = "Date", SortDirection=ListSortDirection.Descending, DisplayFormat= new DateTimeFormatSpecifier() { Locale = "en-UK", DateStyle = "short" }.ToString() }; value.GroupDescriptions.Add(dt); StateHasChanged(); } }
Below is a code-snippet of how to get the format specifier to work for a DateTime grouping:
private DataGrid _grid; public DataGrid GridRef { get { return _grid; } set { _grid = value; var dt = new ColumnGroupDescription() { Field = "Date", DisplayName = "Date", SortDirection = IgniteUI.Blazor.Controls.ListSortDirection.Descending, }; var dFormat = new DateTimeFormatSpecifier() { Locale = "en-UK", DateStyle = "short" }; dt.ValueFormatSpecifiers.Add(dFormat); dt.ValueFormat = "{0}"; _grid.GroupDescriptions.Add(dt); StateHasChanged(); } }
Thanks Andrew - is there a way to use custom formats in there? I tried setting DateStyle to a typical custom format (dd/MM/yyyy) but it didn't work. Apologies if this is documented somewhere - I did search around, but couldn't find anything
There’s no direct way to push custom format in that way directly, as the “format specifiers” are wrappers for the Intl.DateTimeFormat object, seen here.
For example, to create a custom format along the lines of “dd/MM/yyyy” you could use the following:
var dtSpec = new DateTimeFormatSpecifier(); dtSpec.Locale = "en-GB"; dtSpec.Year = "numeric"; dtSpec.Month = "2-digit"; dtSpec.Day = "2-digit";