mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

Avoid scroll when few item: How should be computed numberOfRows in slick.grid.updateRowCount? #1091

Open Adioud opened 8 years ago

Adioud commented 8 years ago

Hi all!

I used to display the grid in a container with a fixed height. The scroll manages well the view when there is too much items... but the problem is that the scroll is always here, even if there is no items!

To fix that, I went to slick.grid.js, in updateRowCount() method, and I found a strange way to compute the number of rows to be displayed, line 1629:

var numberOfRows = dataLengthIncludingAddNew + (options.leaveSpaceForNewRows ? numVisibleRows - 1 : 0);

Replacing the previous line by: var numberOfRows = dataLengthIncludingAddNew + (options.leaveSpaceForNewRows ? 0 : -1);

seems to be OK.

Do you have any feedback or idea about that? Thank you for your help! Adrien

6pac commented 8 years ago

Not sure about this. The non-editable grid scroll bar disappears as soon as the rows fit in the window. It looks like the code you found forces a scroll bar in this situation where the grid is editable.

So I'd say if you don't want that, the change you make is reasonable. I'd have to think about whether that should be changed in the main trunk though, as it's a preference thing. If we make an option setting for that and every other small change, we end up with a zillion option settings. Perhaps it's just best to fork and pull changes from the main repo.

Also, I have a fork that I'm offering as an 'Alternate Master' - an up to date version of the main trunk, if you're interested: https://github.com/6pac/SlickGrid/wiki