hkalbertl / jquery.appendGrid

The dynamic table input JavaScript plugin
https://appendgrid.azurewebsites.net
MIT License
148 stars 77 forks source link

maxRowsAllowed???? #130

Closed drgnbear closed 4 years ago

drgnbear commented 4 years ago

Where did maxRows allowed and it's callback go. I need that feature or a way to program it. There is no beforeRowAdded callback which is what I expected to find. How can I limit the number of rows they are allowed to add?

hkalbertl commented 4 years ago

Hi drgnbear,

Sorry for late reply. maxRowsAllowed was not migrated from v1 yet. I will try to introduce it to v2 very soon. Thanks!

drgnbear commented 4 years ago

I actually figured out an easy work around that has the exact same effect. I can send you the code if you are Interested it may be easier than migrating it. Or at least will give people a quick way to do the same thing in the meantime.

On Dec 16, 2019, at 9:58 PM, Albert L. notifications@github.com wrote:

 Hi drgnbear,

Sorry for late reply. maxRowsAllowed was not migrated from v1 yet. I will try to introduce it to v2 very soon. Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

drgnbear commented 4 years ago

afterRowAppended: function (caller, parentRowIndex, addedRowIndex) { // Make sure AppendGrid is initialized if (weatherAppendGrid) { // Copy data of Foo from parent row to new added rows var parentValue = weatherAppendGrid.getCtrlValue("foo", parentRowIndex); for (var z = 0; z < addedRowIndex.length; z++) { weatherAppendGrid.setCtrlValue("foo", addedRowIndex[z], parentValue); }

//Prevent more than 3 weather cards var rowCount = weatherAppendGrid.getRowCount();

if (rowCount > maxRows) { weatherAppendGrid.removeRow(rowCount - 1); } else if (rowCount === maxRows) { $('.appendgrid-add').hide(); } } }, afterRowRemoved: function (caller, rowIndex) { var rowCount = weatherAppendGrid.getRowCount();

if (rowCount < maxRows) { $('.appendgrid-add').show(); } }

On December 16, 2019 at 9:58 PM, "Albert L." notifications@github.com wrote:

Hi drgnbear,

Sorry for late reply. maxRowsAllowed was not migrated from v1 yet. I will try to introduce it to v2 very soon. Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

hkalbertl commented 4 years ago

Hi drgnbear,

Thank you for your patience and maxRowsAllowed is now available in v2.0.5. Here is a codepen to demonstrate how it works.

Your workaround is also cool to prevent user to add unwanted rows!