//tabledefinition(s) for each table
// the suffix .ingredientsTable has to be changed to the ID of the tablebody where the data will be inserted
tableData = {};
tableData.ingredientsTable = {
'minRows':1,
'maxRows':10,
'td': //the 'td' data is only in the object to show how it could be expanded
{
0: {'class':null,
'innerHTML': 'Table 1 td0 *'
},
1: {'class':null,
'innerHTML': 'Table 1 {placeholder1} td1 *'
},
2: {'class':null,
'innerHTML': 'Table 1 td2 *'
},
3: {'class':null,
'innerHTML': 'Table 1 td3 *'
},
4: { 'class':'actions',
'innerHTML':'<button class=\"insert\" onClick=\"handleTable(this,\'addRowsBefore(1)\')\">+1 ⤒</button>'+
'<button class=\"delete\" onClick=\"handleTable(this,\'deleteRow()\')\">delete</button>'+
'<button class=\"insert\" onClick=\"handleTable(this,\'addRowsAfter(1)\')\">+1 ⤓</button>'
}
}
}
tableData.directionsTable = {
'minRows':1,
'maxRows':8,
}
////********* */
function checkMinRows(tableBody,rowsToDelete) {
let tableId = String(tableBody.closest("table").id);
let minRows = tableData[tableId].minRows;
let currentRows = tableBody.rows.length;
if ((currentRows-rowsToDelete)<minRows) {
return false;
}
else {
return true;
}
}
function checkMaxRows (tableBody,rowsToInsert) {
let tableId = String(tableBody.closest("table").id);
let maxRows = tableData[tableId].maxRows;
let currentRows = tableBody.rows.length;
if ((currentRows+rowsToInsert)>maxRows) {
return false;
}
else {
return true;
}
}
function addRowBeforeCurrentRow (trData) {
let tableBody = trData.closest("tbody");
if (checkMaxRows(tableBody,1) == true) {
let rowId = trData.parentNode.parentNode.id;
let currentRow =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.