anmcgrath / BlazorDatasheet

Simple excel-like datasheet Blazor component
MIT License
131 stars 31 forks source link

Bug: GetViewPort ('0' cannot be greater than -1.) #78

Closed ADefWebserver closed 1 week ago

ADefWebserver commented 1 week ago

In: SimpleExample.razor

Change:

    protected override void OnInitialized()
    {
        sheet = new Sheet(numRows: 100000, numCols: 20000);
    }

To:

    protected override void OnInitialized()
    {
        sheet = new Sheet(numRows: 0, numCols: 20000);
    }

(I am sure you're like "Why??" but in my program I am loading data from a database and the table may be empty. I allow you to add rows so that is why I would want to load an empty table)

When you run it you get:

System.ArgumentException
  HResult=0x80070057
  Message='0' cannot be greater than -1.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Math.ThrowMinMaxException[T](T min, T max)
   at System.Math.Clamp(Int32 value, Int32 min, Int32 max)
   at BlazorDatasheet.Core.Layout.CellLayoutProvider.GetViewPort(Double left, Double top, Double containerWidth, Double containerHeight, Int32 overflowX, Int32 overflowY) in C:\Users\webma\Source\Repos\BlazorDatasheet\src\BlazorDatasheet.Core\Layout\CellLayoutProvider.cs:line 188
   at BlazorDatasheet.Datasheet.HandleScroll(ViewportScrollInfo e) in C:\Users\webma\Source\Repos\BlazorDatasheet\src\BlazorDatasheet\Datasheet.razor.cs:line 333
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

image

image

anmcgrath commented 1 week ago

Hey @ADefWebserver in general I wasn't handling empty rows/columns very well. Please have a look at PR #79 see if it's a reasonable solution.

ADefWebserver commented 1 week ago

@anmcgrath - Yes this is very elegant. This follows the pattern that most Data controls use, to allow a template to be provided when there is no data.