Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tableBuilder(selector) {
- function deleteItems() {
- $(this).parent().parent().remove()
- }
- return {
- createTable: function createTable(columnNames) {
- let htmlHeading = $('<table>');
- let tr = $('<tr>');
- htmlHeading.append(tr);
- for (let names of columnNames) {
- let th = $('<th>').text(names);
- // th.append((names));
- th.appendTo(tr);
- }
- let actionTh = $('<th>');
- actionTh.text('Action');
- actionTh.appendTo(tr);
- $(selector).append(htmlHeading);
- },
- fillData: function fillData(dataRows) {
- let dataRow = $('<tr>');
- for (let row = 0; row < dataRows.length; row++) {
- for (let col = 0; col < dataRows[row].length; col++) {
- let td = $('<td>').text(dataRows[row][col]);
- dataRow.append(td);
- }
- let tableData = $('<td>');
- let deleteBtn = $('<button>Delete</button>').on('click',(deleteItems));
- deleteBtn.appendTo(tableData);
- dataRow.append(tableData);
- $('table').append(dataRow);
- dataRow = $('<tr>');
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement