Closed wlathamIP closed 3 months ago
@wlathamIP you could do as @ADefWebserver suggests and use a custom renderer.
Just added the ability to format dates with the format.NumberFormat. It formats numbers too.
E.g
Sheet.Cells[3, 4].Format = new CellFormat()
{
NumberFormat = "yyyy-MM-dd"
};
@anmcgrath - That is so cool that you added that because it is what a lot of people will need 👍🏽The Custom Render is not needed in that case. However, I do need a TimeOnly to use when binding to a "time" field in my underlying database. It will probably take me a few days to get this fully working, but, so far the ability to create your own Custom Renderers is very promising...
https://github.com/ADefWebserver/BlazorDatasheet/commit/7bee41f9fd78f51f04c0f641dfad277f1053bc0f
Finally got this working...
Use it like this:
<!-- CustomCellTypeDefinitions is for the TimeEditorComponent and TimeRenderer -->
<Datasheet @ref="_datasheet"
CustomCellTypeDefinitions="CustomTypes"
Sheet="sheet"
CanUserMergeRows="false"
ShowColHeadings="true"
ShowRowHeadings="true"
CanUserInsertRows="true"
CanUserRemoveRows="true"
CanUserInsertCols="false"
CanUserRemoveCols="false"
CanUserSort="false" />
</div>
// For the TimeEditorComponent and TimeRenderer
private Dictionary<string, CellTypeDefinition> CustomTypes { get; } = new();
protected override async Task OnInitializedAsync()
{
// For the TimeEditorComponent and TimeRenderer
CustomTypes.Add("time", CellTypeDefinition.Create<TimeEditorComponent, TimeRenderer>());
// Create a new datasheet
sheet = new Sheet(numRows: 100000, numCols: 20000);
await base.OnInitializedAsync();
// Wait 1 second before loading the table data
// to join the UI thread
await Task.Delay(1000);
}
Set a cell to be the 'time' type like this:
sheet.Cells[2, 2].Type = "time";
@anmcgrath - Can you close this?
Is there any way to set a format for how a date is displayed? We've only been able to get it to use MM/DD/YYYY HH:MM:SS but for the data we're working with the timestamp isn't necessary.