<script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script> <script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script> <div class="container"> <h1>Employee Management</h1> <p class="subtitle">Click remove button to delete any row from the table</p> <div class="controls"> <button class="add-btn" onclick="addRow()"> <ion-icon name="add-circle-outline"></ion-icon> Add New Employee </button> </div> <div class="table-wrapper"> <table id="employeeTable"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Position</th> <th>Department</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody id="tableBody"> <tr> <td>#001</td> <td>John Smith</td> <td>Software Engineer</td> <td>Engineering</td> <td><span class="status active">Active</span></td> <td> <button class="remove-btn" onclick="removeRow(this)"> <ion-icon name="trash-outline"></ion-icon> Remove </button> </td> </tr> <tr> <td>#002</td> <td>Sarah Johnson</td> <td>Product Manager</td> <td>Product</td> <td><span class="status active">Active</span></td> <td> <button class="remove-btn" onclick="removeRow(this)"> <ion-icon name="trash-outline"></ion-icon> Remove </button> </td> </tr> <tr> <td>#003</td> <td>Michael Chen</td> <td>UI/UX Designer</td> <td>Design</td> <td><span class="status pending">Pending</span></td> <td> <button class="remove-btn" onclick="removeRow(this)"> <ion-icon name="trash-outline"></ion-icon> Remove </button> </td> </tr> <tr> <td>#004</td> <td>Emily Brown</td> <td>Marketing Lead</td> <td>Marketing</td> <td><span class="status active">Active</span></td> <td> <button class="remove-btn" onclick="removeRow(this)"> <ion-icon name="trash-outline"></ion-icon> Remove </button> </td> </tr> <tr> <td>#005</td> <td>David Wilson</td> <td>Data Analyst</td> <td>Analytics</td> <td><span class="status inactive">Inactive</span></td> <td> <button class="remove-btn" onclick="removeRow(this)"> <ion-icon name="trash-outline"></ion-icon> Remove </button> </td> </tr> </tbody> </table> <div id="emptyState" class="empty-state" style="display: none;"> <ion-icon name="folder-open-outline"></ion-icon> <p>No employees in the table</p> <button class="add-btn" onclick="addRow()"> <ion-icon name="add-circle-outline"></ion-icon> Add Employee </button> </div> </div> </div>
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; background: #f5f7fa; padding: 40px 20px; min-height: 100vh; } .container { max-width: 1000px; margin: 0 auto; } h1 { color: #333; margin-bottom: 10px; font-size: 32px; } .subtitle { color: #666; margin-bottom: 30px; font-size: 16px; } .controls { margin-bottom: 24px; display: flex; gap: 12px; flex-wrap: wrap; } .add-btn { display: flex; align-items: center; gap: 8px; padding: 12px 24px; background: #10b981; color: white; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.3s; } .add-btn:hover { background: #059669; } .add-btn ion-icon { font-size: 20px; } .table-wrapper { background: white; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); overflow: hidden; } table { width: 100%; border-collapse: collapse; } thead { background: #f8f9fa; } th { padding: 16px; text-align: left; font-weight: 600; color: #333; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid #e0e0e0; } tbody tr { border-bottom: 1px solid #f0f0f0; transition: background 0.2s; } tbody tr:hover { background: #f8f9fa; } td { padding: 16px; color: #555; font-size: 15px; } .status { display: inline-block; padding: 4px 12px; border-radius: 12px; font-size: 13px; font-weight: 500; } .status.active { background: #d1fae5; color: #065f46; } .status.pending { background: #fef3c7; color: #92400e; } .status.inactive { background: #fee2e2; color: #991b1b; } .remove-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; background: #ef4444; color: white; border: none; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.3s; } .remove-btn:hover { background: #dc2626; transform: scale(1.05); } .remove-btn ion-icon { font-size: 18px; } .empty-state { text-align: center; padding: 60px 20px; color: #999; } .empty-state ion-icon { font-size: 64px; color: #ddd; margin-bottom: 16px; } .empty-state p { font-size: 16px; margin-bottom: 20px; } @media (max-width: 768px) { .table-wrapper { overflow-x: auto; } table { min-width: 600px; } }
let employeeCounter = 6; // Remove row from table function removeRow(button) { const row = button.closest('tr'); const employeeName = row.cells[1].textContent; // Add fade-out animation row.style.transition = 'opacity 0.3s, transform 0.3s'; row.style.opacity = '0'; row.style.transform = 'translateX(-20px)'; // Remove row after animation setTimeout(() => { row.remove(); checkEmptyState(); }, 300); } // Add new row to table function addRow() { const tableBody = document.getElementById('tableBody'); const names = ['Alice Cooper', 'Bob Taylor', 'Carol White', 'Daniel Lee', 'Emma Davis']; const positions = ['Developer', 'Designer', 'Manager', 'Analyst', 'Consultant']; const departments = ['Engineering', 'Design', 'Management', 'Analytics', 'Operations']; const statuses = ['active', 'pending', 'inactive']; const randomName = names[Math.floor(Math.random() * names.length)]; const randomPosition = positions[Math.floor(Math.random() * positions.length)]; const randomDepartment = departments[Math.floor(Math.random() * departments.length)]; const randomStatus = statuses[Math.floor(Math.random() * statuses.length)]; const newRow = document.createElement('tr'); newRow.innerHTML = ` <td>#${String(employeeCounter).padStart(3, '0')}</td> <td>${randomName}</td> <td>${randomPosition}</td> <td>${randomDepartment}</td> <td><span class="status ${randomStatus}">${randomStatus.charAt(0).toUpperCase() + randomStatus.slice(1)}</span></td> <td> <button class="remove-btn" onclick="removeRow(this)"> <ion-icon name="trash-outline"></ion-icon> Remove </button> </td> `; // Add fade-in animation newRow.style.opacity = '0'; newRow.style.transform = 'translateX(-20px)'; tableBody.appendChild(newRow); setTimeout(() => { newRow.style.transition = 'opacity 0.3s, transform 0.3s'; newRow.style.opacity = '1'; newRow.style.transform = 'translateX(0)'; }, 10); employeeCounter++; checkEmptyState(); } // Check if table is empty and show/hide empty state function checkEmptyState() { const tableBody = document.getElementById('tableBody'); const emptyState = document.getElementById('emptyState'); const table = document.getElementById('employeeTable'); if (tableBody.children.length === 0) { table.style.display = 'none'; emptyState.style.display = 'block'; } else { table.style.display = 'table'; emptyState.style.display = 'none'; } }
Login to leave a comment
No comments yet. Be the first!
View Project
No comments yet. Be the first!