5

I have a handsontable table which is dynamic, meaning data can be added after initiation. The problem is, however, that new rows can be added to the table when dragging down while clicking the corner of a cell. How would I prevent users from expanding the table while making sure I can still add new rows if one would interact with a button for example.

I tried using

afterCreateRow: function(index, amount){ data.splice(index, amount) },

but that prevents me from adding new rows using the alter function. If this question was rather vague: See the link below for a default jsfiddle with handsontable. Click the corner of a cell and drag down, you'll see.

http://jsfiddle.net/warpech/hU6Kz/

TL;DR: Disable row creation when dragging cells, allow row creation using (in code) handsontable.alter('insert_row');

Thanks in advance.

Dubb
  • 423
  • 1
  • 7
  • 21

3 Answers3

4

You can add this code to prevent row creation when you are dragging cells :

fillHandle: {
    autoInsertRow: false,
},
Joakim Si Ali
  • 502
  • 4
  • 13
  • Hello, sorry for the late reply. Unfortunately your answer didn't solve it. I don't see a change regarding the problem. Thanks though! – Dubb Aug 08 '16 at 06:02
2

EDIT: Check out this fiddle.

So I added this

fillHandle: {
    autoInsertRow: false
}

and removed minSpareRows: 1.

This gives you the drag functionality without the automatic creation of rows.

To test:

If you right-click and manually insert a row (Insert row below), and then click and drag some value into the new row using the fill handle, it should paste the value in without creating a new row underneath.

Note: If you need the same functionality horizontally (aka, being able to drag values horizontally without auto-creating new columns) remove minSparecols: 1

Hope this is what you're looking for!


Add the fillHandle: false option to your current options.

This removes the ability to drag and create new rows, but still leaves you with the ability to add new rows via the context menu (contextMenu: true) and the minimum spare rows option (minSpareRows: 1).

adriennetacke
  • 1,726
  • 1
  • 14
  • 21
  • Hey! Thanks for your response. Your solution did solve the creation of new rows by dragging, but it also removes the ability to easily copy data by dragging in existing rows. Is it possible to allow dragging on existing rows but cancel the creation of new rows while dragging? – Dubb Aug 08 '16 at 06:18
  • I think you can still drag and select multiple rows without creating new ones. Could you explain a bit more? – adriennetacke Aug 08 '16 at 06:46
  • Basically, if a cell has a value and I drag that cell, like I would drag it when it created a new row, the cells underneath it would receive the same value (like in excel). However, now that the entire drag function is gone I cannot use that feature anymore. By dragging I mean using the little cross icon when you hover on a corner. @adriennetacke – Dubb Aug 08 '16 at 07:50
  • Oh, that might be conflicting functionality. Let me check the docs a bit and I'll get back to you. – adriennetacke Aug 08 '16 at 19:06
  • @Dubb Check out my edit. Is this what you're looking for? – adriennetacke Aug 08 '16 at 21:11
0

I understand your problem, I was in same situation.

I have solved with this:

maxRows: getFixedNumberOfRows(),
minRows: getFixedNumberOfRows(),

With this solution you can keep drag and drop for easy fill cells, and avoid add rows at the end

If anyone knows a better solution is welcome

Dani
  • 1,825
  • 2
  • 15
  • 29