File size: 36,067 Bytes
c592faa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TanStack Table with TailwindCSS</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://unpkg.com/@tanstack/table-core@8.9.3/build/umd/index.production.js"></script>
    <style>
        /* Custom scrollbar for table */
        .table-container::-webkit-scrollbar {
            height: 8px;
            width: 8px;
        }
        .table-container::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 4px;
        }
        .table-container::-webkit-scrollbar-thumb {
            background: #888;
            border-radius: 4px;
        }
        .table-container::-webkit-scrollbar-thumb:hover {
            background: #555;
        }
        
        /* Animation for row hover */
        @keyframes rowHover {
            0% { background-color: inherit; }
            100% { background-color: #f8fafc; }
        }
        
        .animate-row-hover:hover {
            animation: rowHover 0.2s ease-out forwards;
        }
        
        /* Loading spinner */
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .loading-spinner {
            animation: spin 1s linear infinite;
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 mb-8">
            <div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-6 gap-4">
                <div>
                    <h1 class="text-2xl font-bold text-gray-800">Employee Directory</h1>
                    <p class="text-gray-600">Manage your organization's employees</p>
                </div>
                <div class="flex flex-col sm:flex-row gap-3 w-full md:w-auto">
                    <div class="relative flex-grow">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fas fa-search text-gray-400"></i>
                        </div>
                        <input 
                            type="text" 
                            id="searchInput" 
                            placeholder="Search employees..." 
                            class="pl-10 pr-4 py-2 border border-gray-300 rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
                        >
                    </div>
                    <button 
                        id="addEmployeeBtn"
                        class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center justify-center gap-2 transition-colors"
                    >
                        <i class="fas fa-plus"></i>
                        <span>Add Employee</span>
                    </button>
                </div>
            </div>
            
            <div class="flex flex-wrap items-center justify-between gap-3 mb-4">
                <div class="flex items-center gap-2">
                    <label for="statusFilter" class="text-sm font-medium text-gray-700">Status:</label>
                    <select 
                        id="statusFilter" 
                        class="border border-gray-300 rounded-md px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
                    >
                        <option value="all">All</option>
                        <option value="active">Active</option>
                        <option value="inactive">Inactive</option>
                        <option value="on-leave">On Leave</option>
                    </select>
                </div>
                
                <div class="flex items-center gap-2">
                    <label class="text-sm font-medium text-gray-700">Department:</label>
                    <div class="flex flex-wrap gap-2">
                        <button data-dept="all" class="department-pill px-3 py-1 rounded-full text-xs bg-blue-100 text-blue-800 border border-blue-200 hover:bg-blue-200 active:bg-blue-300">
                            All
                        </button>
                        <button data-dept="Engineering" class="department-pill px-3 py-1 rounded-full text-xs bg-blue-100 text-blue-800 border border-blue-200 hover:bg-blue-200 active:bg-blue-300">
                            Engineering
                        </button>
                        <button data-dept="Marketing" class="department-pill px-3 py-1 rounded-full text-xs bg-purple-100 text-purple-800 border border-purple-200 hover:bg-purple-200 active:bg-purple-300">
                            Marketing
                        </button>
                        <button data-dept="Sales" class="department-pill px-3 py-1 rounded-full text-xs bg-green-100 text-green-800 border border-green-200 hover:bg-green-200 active:bg-green-300">
                            Sales
                        </button>
                        <button data-dept="HR" class="department-pill px-3 py-1 rounded-full text-xs bg-pink-100 text-pink-800 border border-pink-200 hover:bg-pink-200 active:bg-pink-300">
                            HR
                        </button>
                        <button data-dept="Finance" class="department-pill px-3 py-1 rounded-full text-xs bg-yellow-100 text-yellow-800 border border-yellow-200 hover:bg-yellow-200 active:bg-yellow-300">
                            Finance
                        </button>
                        <button data-dept="Product" class="department-pill px-3 py-1 rounded-full text-xs bg-indigo-100 text-indigo-800 border border-indigo-200 hover:bg-indigo-200 active:bg-indigo-300">
                            Product
                        </button>
                        <button data-dept="Design" class="department-pill px-3 py-1 rounded-full text-xs bg-red-100 text-red-800 border border-red-200 hover:bg-red-200 active:bg-red-300">
                            Design
                        </button>
                        <button data-dept="Operations" class="department-pill px-3 py-1 rounded-full text-xs bg-gray-100 text-gray-800 border border-gray-200 hover:bg-gray-200 active:bg-gray-300">
                            Operations
                        </button>
                    </div>
                </div>
                
                <div class="flex items-center gap-2">
                    <label for="rowsPerPage" class="text-sm font-medium text-gray-700">Rows:</label>
                    <select 
                        id="rowsPerPage" 
                        class="border border-gray-300 rounded-md px-3 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
                    >
                        <option value="5">5</option>
                        <option value="10" selected>10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                    </select>
                </div>
            </div>
            
            <div class="table-container overflow-x-auto rounded-lg border border-gray-200">
                <div id="loadingIndicator" class="hidden p-8 flex items-center justify-center">
                    <div class="loading-spinner h-8 w-8 border-4 border-blue-500 border-t-transparent rounded-full"></div>
                </div>
                <table id="dataTable" class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr id="tableHeader"></tr>
                    </thead>
                    <tbody id="tableBody" class="bg-white divide-y divide-gray-200"></tbody>
                </table>
            </div>
            
            <div class="flex flex-col sm:flex-row items-center justify-between mt-4 gap-4">
                <div class="text-sm text-gray-600">
                    Showing <span id="showingFrom">1</span> to <span id="showingTo">10</span> of <span id="totalItems">50</span> entries
                </div>
                
                <div class="flex items-center gap-2">
                    <button id="firstPage" class="px-3 py-1 border rounded-md disabled:opacity-50">
                        <i class="fas fa-angle-double-left"></i>
                    </button>
                    <button id="prevPage" class="px-3 py-1 border rounded-md disabled:opacity-50">
                        <i class="fas fa-angle-left"></i>
                    </button>
                    <div id="pageNumbers" class="flex gap-1"></div>
                    <button id="nextPage" class="px-3 py-1 border rounded-md disabled:opacity-50">
                        <i class="fas fa-angle-right"></i>
                    </button>
                    <button id="lastPage" class="px-3 py-1 border rounded-md disabled:opacity-50">
                        <i class="fas fa-angle-double-right"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Employee Modal -->
    <div id="employeeModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-xl shadow-xl w-full max-w-md mx-4">
            <div class="flex justify-between items-center border-b px-6 py-4">
                <h3 class="text-lg font-semibold" id="modalTitle">Add Employee</h3>
                <button id="closeModal" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-6">
                <form id="employeeForm">
                    <div class="mb-4">
                        <label for="name" class="block text-sm font-medium text-gray-700 mb-1">Full Name</label>
                        <input type="text" id="name" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500">
                    </div>
                    <div class="mb-4">
                        <label for="position" class="block text-sm font-medium text-gray-700 mb-1">Position</label>
                        <input type="text" id="position" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500">
                    </div>
                    <div class="mb-4">
                        <label for="department" class="block text-sm font-medium text-gray-700 mb-1">Department</label>
                        <select id="department" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500">
                            <option value="Engineering">Engineering</option>
                            <option value="Marketing">Marketing</option>
                            <option value="Sales">Sales</option>
                            <option value="HR">Human Resources</option>
                            <option value="Finance">Finance</option>
                        </select>
                    </div>
                    <div class="mb-4">
                        <label for="status" class="block text-sm font-medium text-gray-700 mb-1">Status</label>
                        <select id="status" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500">
                            <option value="active">Active</option>
                            <option value="inactive">Inactive</option>
                            <option value="on-leave">On Leave</option>
                        </select>
                    </div>
                    <div class="flex justify-end gap-3 mt-6">
                        <button type="button" id="cancelBtn" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">Cancel</button>
                        <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        // Sample data (100 entries)
        const departments = ['Engineering', 'Marketing', 'Sales', 'HR', 'Finance', 'Product', 'Design', 'Operations'];
        const positions = {
            Engineering: ['Software Engineer', 'Frontend Developer', 'Backend Developer', 'DevOps Engineer', 'QA Engineer', 'Data Engineer'],
            Marketing: ['Marketing Specialist', 'Content Writer', 'SEO Specialist', 'Social Media Manager'],
            Sales: ['Sales Executive', 'Sales Manager', 'Account Executive', 'Business Development'],
            HR: ['HR Coordinator', 'Recruiter', 'HR Manager', 'Talent Acquisition'],
            Finance: ['Finance Manager', 'Accountant', 'Financial Analyst', 'Controller'],
            Product: ['Product Manager', 'Product Owner', 'Product Designer'],
            Design: ['UX Designer', 'UI Designer', 'Graphic Designer'],
            Operations: ['Operations Manager', 'Office Administrator']
        };
        const statuses = ['active', 'inactive', 'on-leave'];
        
        const firstNames = ['John', 'Jane', 'Robert', 'Emily', 'Michael', 'Sarah', 'David', 'Jessica', 'Thomas', 'Lisa', 'William', 'Karen', 'James', 'Nancy', 'Daniel', 'Jennifer', 'Richard', 'Susan', 'Joseph', 'Margaret'];
        const lastNames = ['Doe', 'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Rodriguez', 'Wilson', 'Martinez', 'Anderson', 'Taylor', 'Thomas', 'Lee', 'Perez', 'Thompson', 'White', 'Harris'];
        
        const data = [];
        for (let i = 1; i <= 100; i++) {
            const dept = departments[Math.floor(Math.random() * departments.length)];
            const pos = positions[dept][Math.floor(Math.random() * positions[dept].length)];
            const status = statuses[Math.floor(Math.random() * statuses.length)];
            const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
            const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
            const joinDate = new Date(2018 + Math.floor(Math.random() * 5), Math.floor(Math.random() * 12), Math.floor(Math.random() * 28) + 1);
            
            data.push({
                id: i,
                name: `${firstName} ${lastName}`,
                position: pos,
                department: dept,
                status: status,
                joinDate: joinDate.toISOString().split('T')[0]
            });
        }

        // Initialize TanStack Table
        const table = window.TanStackTableCore;
        
        // Column definitions
        const columns = [
            {
                accessorKey: 'id',
                header: 'ID',
                size: 80,
                cell: info => info.getValue(),
            },
            {
                accessorKey: 'name',
                header: 'Name',
                cell: info => {
                    const name = info.getValue();
                    return `<div class="flex items-center gap-3">
                        <div class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 font-medium">
                            ${name.charAt(0)}
                        </div>
                        <span class="font-medium">${name}</span>
                    </div>`;
                },
            },
            {
                accessorKey: 'position',
                header: 'Position',
                cell: info => `<span class="text-gray-700">${info.getValue()}</span>`,
            },
            {
                accessorKey: 'department',
                header: 'Department',
                cell: info => {
                    const dept = info.getValue();
                    let bgColor = 'bg-gray-100 text-gray-800';
                    if (dept === 'Engineering') bgColor = 'bg-blue-100 text-blue-800';
                    if (dept === 'Marketing') bgColor = 'bg-purple-100 text-purple-800';
                    if (dept === 'Sales') bgColor = 'bg-green-100 text-green-800';
                    if (dept === 'HR') bgColor = 'bg-pink-100 text-pink-800';
                    if (dept === 'Finance') bgColor = 'bg-yellow-100 text-yellow-800';
                    
                    return `<span class="px-2 py-1 text-xs rounded-full ${bgColor}">${dept}</span>`;
                },
            },
            {
                accessorKey: 'status',
                header: 'Status',
                cell: info => {
                    const status = info.getValue();
                    let bgColor = 'bg-gray-100 text-gray-800';
                    let icon = 'fa-circle';
                    if (status === 'active') {
                        bgColor = 'bg-green-100 text-green-800';
                        icon = 'fa-check-circle';
                    }
                    if (status === 'inactive') {
                        bgColor = 'bg-red-100 text-red-800';
                        icon = 'fa-times-circle';
                    }
                    if (status === 'on-leave') {
                        bgColor = 'bg-yellow-100 text-yellow-800';
                        icon = 'fa-umbrella-beach';
                    }
                    
                    return `<div class="flex items-center gap-2">
                        <i class="fas ${icon} text-xs"></i>
                        <span class="capitalize">${status}</span>
                    </div>`;
                },
            },
            {
                accessorKey: 'joinDate',
                header: 'Join Date',
                cell: info => {
                    const date = new Date(info.getValue());
                    return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
                },
            },
            {
                id: 'actions',
                header: 'Actions',
                cell: info => {
                    return `<div class="flex gap-2">
                        <button class="edit-btn px-2 py-1 text-blue-600 hover:text-blue-800" data-id="${info.row.original.id}">
                            <i class="fas fa-edit"></i>
                        </button>
                        <button class="delete-btn px-2 py-1 text-red-600 hover:text-red-800" data-id="${info.row.original.id}">
                            <i class="fas fa-trash"></i>
                        </button>
                    </div>`;
                },
            },
        ];

        // Table state
        let tableState = {
            data: [...data],
            columns,
            pagination: {
                pageIndex: 0,
                pageSize: 10,
            },
            sorting: [],
            globalFilter: '',
            columnFilters: [],
        };

        // Initialize table instance
        const tableInstance = table.createTable({
            data: [...data], // Ensure fresh data is passed
            columns: tableState.columns,
            state: {
                pagination: tableState.pagination,
                sorting: tableState.sorting,
                globalFilter: tableState.globalFilter,
                columnFilters: tableState.columnFilters,
            },
            initialState: {
                pagination: {
                    pageSize: 10
                }
            },
            onPaginationChange: updater => {
                tableState.pagination = typeof updater === 'function' ? updater(tableState.pagination) : updater;
                renderTable();
            },
            onSortingChange: updater => {
                tableState.sorting = typeof updater === 'function' ? updater(tableState.sorting) : updater;
                renderTable();
            },
            onGlobalFilterChange: updater => {
                tableState.globalFilter = typeof updater === 'function' ? updater(tableState.globalFilter) : updater;
                tableState.pagination.pageIndex = 0; // Reset to first page on filter
                renderTable();
            },
            onColumnFiltersChange: updater => {
                tableState.columnFilters = typeof updater === 'function' ? updater(tableState.columnFilters) : updater;
                tableState.pagination.pageIndex = 0; // Reset to first page on filter
                renderTable();
            },
            getCoreRowModel: table.getCoreRowModel(),
            getSortedRowModel: table.getSortedRowModel(),
            getFilteredRowModel: table.getFilteredRowModel(),
            getPaginationRowModel: table.getPaginationRowModel(),
        });

        // Render table function
        function renderTable() {
            // Show loading indicator
            document.getElementById('loadingIndicator').classList.remove('hidden');
            document.getElementById('dataTable').classList.add('opacity-50');
            
            // Simulate loading delay
            setTimeout(() => {
                // Get filtered/sorted/paginated data
                const headerGroups = tableInstance.getHeaderGroups();
                const rowModel = tableInstance.getRowModel();
                
                console.log('Row model rows:', rowModel.rows); // Debugging
                
                // Render header
                const headerRow = document.getElementById('tableHeader');
                headerRow.innerHTML = '';
                
                headerGroups[0].headers.forEach(header => {
                    const th = document.createElement('th');
                    th.className = 'px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider';
                    th.style.width = `${header.getSize()}px`;
                    
                    const canSort = header.column.getCanSort();
                    
                    if (canSort) {
                        th.className += ' cursor-pointer hover:bg-gray-100';
                        th.onclick = header.column.getToggleSortingHandler();
                    }
                    
                    const sortDirection = header.column.getIsSorted();
                    let sortIcon = '';
                    
                    if (sortDirection === 'asc') {
                        sortIcon = '<i class="fas fa-sort-up ml-1"></i>';
                    } else if (sortDirection === 'desc') {
                        sortIcon = '<i class="fas fa-sort-down ml-1"></i>';
                    } else if (canSort) {
                        sortIcon = '<i class="fas fa-sort ml-1 text-gray-300"></i>';
                    }
                    
                    th.innerHTML = `<div class="flex items-center">${header.column.columnDef.header}${sortIcon}</div>`;
                    headerRow.appendChild(th);
                });
                
                // Render body
                const tableBody = document.getElementById('tableBody');
                tableBody.innerHTML = '';
                
                rowModel.rows.forEach(row => {
                    const tr = document.createElement('tr');
                    tr.className = 'animate-row-hover';
                    
                    row.getVisibleCells().forEach(cell => {
                        const td = document.createElement('td');
                        td.className = 'px-6 py-4 whitespace-nowrap';
                        td.innerHTML = cell.column.columnDef.cell(cell);
                        tr.appendChild(td);
                    });
                    
                    tableBody.appendChild(tr);
                });
                
                // Update pagination info
                const pageCount = tableInstance.getPageCount();
                const currentPage = tableInstance.getState().pagination.pageIndex;
                const pageSize = tableInstance.getState().pagination.pageSize;
                const totalItems = tableInstance.getFilteredRowModel().rows.length;
                
                document.getElementById('showingFrom').textContent = (currentPage * pageSize) + 1;
                document.getElementById('showingTo').textContent = Math.min((currentPage + 1) * pageSize, totalItems);
                document.getElementById('totalItems').textContent = totalItems;
                
                // Render pagination buttons
                const pageNumbers = document.getElementById('pageNumbers');
                pageNumbers.innerHTML = '';
                
                const maxVisiblePages = 5;
                let startPage = Math.max(0, currentPage - Math.floor(maxVisiblePages / 2));
                let endPage = Math.min(pageCount - 1, startPage + maxVisiblePages - 1);
                
                if (endPage - startPage + 1 < maxVisiblePages) {
                    startPage = Math.max(0, endPage - maxVisiblePages + 1);
                }
                
                // Always show first page if not visible
                if (startPage > 0) {
                    const firstPageBtn = document.createElement('button');
                    firstPageBtn.className = `px-3 py-1 border rounded-md ${currentPage === 0 ? 'bg-blue-100 border-blue-300' : ''}`;
                    firstPageBtn.textContent = '1';
                    firstPageBtn.onclick = () => tableInstance.setPageIndex(0);
                    pageNumbers.appendChild(firstPageBtn);
                    
                    if (startPage > 1) {
                        const ellipsis = document.createElement('span');
                        ellipsis.className = 'px-2';
                        ellipsis.textContent = '...';
                        pageNumbers.appendChild(ellipsis);
                    }
                }
                
                for (let i = startPage; i <= endPage; i++) {
                    const pageBtn = document.createElement('button');
                    pageBtn.className = `px-3 py-1 border rounded-md ${currentPage === i ? 'bg-blue-100 border-blue-300' : ''}`;
                    pageBtn.textContent = i + 1;
                    pageBtn.onclick = () => tableInstance.setPageIndex(i);
                    pageNumbers.appendChild(pageBtn);
                }
                
                // Always show last page if not visible
                if (endPage < pageCount - 1) {
                    if (endPage < pageCount - 2) {
                        const ellipsis = document.createElement('span');
                        ellipsis.className = 'px-2';
                        ellipsis.textContent = '...';
                        pageNumbers.appendChild(ellipsis);
                    }
                    
                    const lastPageBtn = document.createElement('button');
                    lastPageBtn.className = `px-3 py-1 border rounded-md ${currentPage === pageCount - 1 ? 'bg-blue-100 border-blue-300' : ''}`;
                    lastPageBtn.textContent = pageCount;
                    lastPageBtn.onclick = () => tableInstance.setPageIndex(pageCount - 1);
                    pageNumbers.appendChild(lastPageBtn);
                }
                
                // Update pagination button states
                document.getElementById('firstPage').disabled = currentPage === 0;
                document.getElementById('prevPage').disabled = currentPage === 0;
                document.getElementById('nextPage').disabled = currentPage >= pageCount - 1;
                document.getElementById('lastPage').disabled = currentPage >= pageCount - 1;
                
                // Hide loading indicator
                document.getElementById('loadingIndicator').classList.add('hidden');
                document.getElementById('dataTable').classList.remove('opacity-50');
            }, 300);
        }

        // Initial render
        console.log('Initial data:', data); // Debugging
        console.log('Table instance:', tableInstance); // Debugging
        renderTable();

        // Event listeners
        document.getElementById('searchInput').addEventListener('input', (e) => {
            tableInstance.setGlobalFilter(e.target.value);
        });

        document.getElementById('statusFilter').addEventListener('change', (e) => {
            if (e.target.value === 'all') {
                tableInstance.setColumnFilters(tableState.columnFilters.filter(f => f.id !== 'status'));
            } else {
                tableInstance.setColumnFilters([
                    ...tableState.columnFilters.filter(f => f.id !== 'status'),
                    { id: 'status', value: e.target.value }
                ]);
            }
        });

        // Department pill tabs event delegation
        document.addEventListener('click', (e) => {
            if (e.target.closest('.department-pill')) {
                const dept = e.target.closest('.department-pill').getAttribute('data-dept');
                
                // Update active state
                document.querySelectorAll('.department-pill').forEach(btn => {
                    btn.classList.remove('bg-blue-600', 'text-white');
                    btn.classList.add(btn.classList.contains('bg-blue-100') ? 'bg-blue-100' : 
                                    btn.classList.contains('bg-purple-100') ? 'bg-purple-100' :
                                    btn.classList.contains('bg-green-100') ? 'bg-green-100' :
                                    btn.classList.contains('bg-pink-100') ? 'bg-pink-100' :
                                    btn.classList.contains('bg-yellow-100') ? 'bg-yellow-100' :
                                    btn.classList.contains('bg-indigo-100') ? 'bg-indigo-100' :
                                    btn.classList.contains('bg-red-100') ? 'bg-red-100' : 'bg-gray-100');
                });
                
                if (dept === 'all') {
                    tableInstance.setColumnFilters(tableState.columnFilters.filter(f => f.id !== 'department'));
                } else {
                    e.target.closest('.department-pill').classList.remove('bg-blue-100', 'bg-purple-100', 'bg-green-100', 'bg-pink-100', 'bg-yellow-100', 'bg-indigo-100', 'bg-red-100', 'bg-gray-100');
                    e.target.closest('.department-pill').classList.add('bg-blue-600', 'text-white');
                    tableInstance.setColumnFilters([
                        ...tableState.columnFilters.filter(f => f.id !== 'department'),
                        { id: 'department', value: dept }
                    ]);
                }
            }
        });

        document.getElementById('rowsPerPage').addEventListener('change', (e) => {
            tableInstance.setPageSize(Number(e.target.value));
        });

        document.getElementById('firstPage').addEventListener('click', () => {
            tableInstance.setPageIndex(0);
        });

        document.getElementById('prevPage').addEventListener('click', () => {
            tableInstance.previousPage();
        });

        document.getElementById('nextPage').addEventListener('click', () => {
            tableInstance.nextPage();
        });

        document.getElementById('lastPage').addEventListener('click', () => {
            tableInstance.setPageIndex(tableInstance.getPageCount() - 1);
        });

        // Modal functionality
        const modal = document.getElementById('employeeModal');
        const addEmployeeBtn = document.getElementById('addEmployeeBtn');
        const closeModal = document.getElementById('closeModal');
        const cancelBtn = document.getElementById('cancelBtn');
        const employeeForm = document.getElementById('employeeForm');
        
        let currentEditId = null;
        
        function openModal(employee = null) {
            if (employee) {
                document.getElementById('modalTitle').textContent = 'Edit Employee';
                document.getElementById('name').value = employee.name;
                document.getElementById('position').value = employee.position;
                document.getElementById('department').value = employee.department;
                document.getElementById('status').value = employee.status;
                currentEditId = employee.id;
            } else {
                document.getElementById('modalTitle').textContent = 'Add Employee';
                employeeForm.reset();
                currentEditId = null;
            }
            modal.classList.remove('hidden');
        }
        
        function closeModalHandler() {
            modal.classList.add('hidden');
        }
        
        addEmployeeBtn.addEventListener('click', () => openModal());
        closeModal.addEventListener('click', closeModalHandler);
        cancelBtn.addEventListener('click', closeModalHandler);
        
        // Handle form submission
        employeeForm.addEventListener('submit', (e) => {
            e.preventDefault();
            
            const newEmployee = {
                id: currentEditId || Math.max(...tableState.data.map(e => e.id)) + 1,
                name: document.getElementById('name').value,
                position: document.getElementById('position').value,
                department: document.getElementById('department').value,
                status: document.getElementById('status').value,
                joinDate: new Date().toISOString().split('T')[0],
            };
            
            if (currentEditId) {
                // Update existing employee
                const index = tableState.data.findIndex(e => e.id === currentEditId);
                if (index !== -1) {
                    tableState.data[index] = newEmployee;
                }
            } else {
                // Add new employee
                tableState.data.unshift(newEmployee);
            }
            
            // Reset table state and render
            tableState.pagination.pageIndex = 0;
            tableInstance.setData([...tableState.data]);
            renderTable();
            
            closeModalHandler();
        });
        
        // Handle edit and delete buttons (delegated events)
        document.addEventListener('click', (e) => {
            // Edit button
            if (e.target.closest('.edit-btn')) {
                const id = parseInt(e.target.closest('.edit-btn').getAttribute('data-id'));
                const employee = tableState.data.find(e => e.id === id);
                if (employee) {
                    openModal(employee);
                }
            }
            
            // Delete button
            if (e.target.closest('.delete-btn')) {
                const id = parseInt(e.target.closest('.delete-btn').getAttribute('data-id'));
                if (confirm('Are you sure you want to delete this employee?')) {
                    tableState.data = tableState.data.filter(e => e.id !== id);
                    tableInstance.setData([...tableState.data]);
                    renderTable();
                }
            }
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=etrano/zz" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>