Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maxSpareCols/ maxSpareRows options #225

Closed
deeta opened this issue Nov 5, 2012 · 17 comments
Closed

Add maxSpareCols/ maxSpareRows options #225

deeta opened this issue Nov 5, 2012 · 17 comments

Comments

@deeta
Copy link

deeta commented Nov 5, 2012

Is there a way to set a max spare rows property?

For example: start with minSpareRows: 1 and create up to a maximum of n rows

@MuyBien
Copy link

MuyBien commented Nov 8, 2012

Hi deeta !
Maybe you can use the onChange property to launch a function that use handsontable('countRows') to fix the limit ?

@deeta
Copy link
Author

deeta commented Nov 8, 2012

Thanks MuyBien, this is what i am currently doing as a work around, but changing the settings in onChange to limit Rows has some unhandled errors. One case was when user copies more rows (20 rows for example) and pastes into this table which limits at 10 rows.

I was thinking it would be easy and clean to set it directly on handsontable during init

@warpech
Copy link
Member

warpech commented Nov 25, 2012

Working on it right now, will be in 0.7.5

@warpech
Copy link
Member

warpech commented Nov 26, 2012

Now the settings minRows, minCols, maxRows and maxCols are available

@ghost
Copy link

ghost commented Jun 20, 2018

@warpech Hey man!

As far as I understand none of the mentioned settings addresses the original request. The closest one is maxCols but it limits the maximum amount of columns while desired ability is to limit maximum amount of spare columns.

With that, am I missing something or should we re-open this issue?

@AMBudnik
Copy link
Contributor

Hi @jouyuy

what is the scenario of adding rows in your project?

maxCols limits the dataset when it's bigger than a value used for the option - http://jsfiddle.net/05mekuon/, it doesn't have any impact od data with fewer columns - http://jsfiddle.net/v4hutwj5/ and it cuts the minSpareCols to fit the exact number of defined columns in the maxCols option - http://jsfiddle.net/xr48z2f5/

@ghost
Copy link

ghost commented Jun 26, 2018

@AMBudnik

Imagine the following scenario:

  1. We have a table with single row.
  2. maxCols is unset because we don't want to limit maximum amount of columns.
  3. minSpareCols is set to 1 so that every time all cells are filled out a blank one appears.

What I need is to limit the maximum amount of spare columns so that there is always 1 spare column. When using minSpareCols with unset maxCols you can actually create as many spare columns as you want.

I found a way to achieve desired behaviour by combining dynamic maxCols (watch for data changes and set it to current columns count + 1) and minSpareCols set to 1. However, I think that maxSpareCols would provide a more clean/straightforward solution for this.

@AMBudnik
Copy link
Contributor

You should also be able to determine if your table should add a spare column by checking isEmptyCol via beforeCreateCol hook

@ghost
Copy link

ghost commented Jun 27, 2018

@AMBudnik

What do I do if I find out that I shouldn't add that column in beforeCreateCol hook? After your suggestion I expected to be able to return something like false from the beforeCreateCol in order to prevent that column from being added, but I looked it up in the documentation and didn't find anything like that.

@AMBudnik
Copy link
Contributor

sorry @jouyuy

I should have asked you for some details first. How a user is able to add a blank column: menu, data erase, autofill, context menu? It defines a hook that can be used here.

@ghost
Copy link

ghost commented Jul 1, 2018

@AMBudnik User is not explicitly able to add a blank column - it gets added automatically as soon as all cells have values.

@AMBudnik
Copy link
Contributor

AMBudnik commented Jul 2, 2018

Can you share a scenario where the column is being added against your requirements?

@ghost
Copy link

ghost commented Jul 2, 2018

@AMBudnik I can think of at least 3 ways to end up with more than 1 spare columns in my case (i.e. when you have maxRows/minSpareCols set to 1 and unset maxCols):

  1. Spam TAB key which adds a new cell as soon as you reach the end of a row.
  2. Use autofill feature which adds a new cell as soon as you reach the end of a row.
  3. Simply clear one of the existing cells.

@AMBudnik
Copy link
Contributor

AMBudnik commented Jul 4, 2018

Thank you for sharing the details. We should remember that if a column already had a value but it has been erased manually by a user action it's value is " " (an empty string), so we can track it via afterChange.
Here is http://jsfiddle.net/fhp859x6/ what I would use to get rid of extra columns.

@ghost
Copy link

ghost commented Jul 4, 2018

@AMBudnik Your example doesn't handle 1st scenario (which is spamming TAB key), but as I said I've already found a suitable solution. I just thought that having maxSpareCols would make things easier and help to keep the code clean.

@AMBudnik
Copy link
Contributor

AMBudnik commented Jul 4, 2018

Actually, I can mark this topic as a feature request.

@AMBudnik AMBudnik changed the title How to limit the number of spare rows that can be created? Add maxSpareCols option Jul 4, 2018
@AMBudnik AMBudnik reopened this Jul 4, 2018
@AMBudnik AMBudnik changed the title Add maxSpareCols option Add maxSpareCols/ maxSpareRows options Jul 4, 2018
@AMBudnik
Copy link
Contributor

AMBudnik commented Dec 6, 2018

This feature request is closed. It will be automatically reopened after we attach it to a milestone.
Thank you very much for share it. I hope that we'll be able to publish it soon.

@AMBudnik AMBudnik closed this as completed Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants