# Tables
Concept includes both Bootstrap 5 tables and DataTables v2.2.3 with Bootstrap 5 styling for advanced functionality.
## Concept Table Configuration
### Table Variables
```scss
// From Concept's _variables.scss
$table-cell-padding-y: 0.75rem;
$table-cell-padding-x: 0.75rem;
$body-color: #3d405c;
$border-color: #e6e6f2;
```
### Basic Table Structure
From Concept's general-tables.html:
```html
| # |
Name |
Email |
Status |
| 1 |
John Doe |
john@example.com |
Active |
```
### Table Variants
```html
```
### Responsive Tables
```html
```
## DataTables Integration
Concept uses DataTables with Bootstrap 5 styling. From data-tables.html:
```html
| Name |
Position |
Office |
Age |
Start date |
Salary |
| Tiger Nixon |
System Architect |
Edinburgh |
61 |
2011/04/25 |
$320,800 |
```
### DataTable with Options
```javascript
new DataTable('#advancedTable', {
// Pagination
pageLength: 25,
lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
// Sorting
order: [[1, 'asc']],
// Search
searching: true,
// Info
info: true,
// Responsive
responsive: true,
// Language
language: {
search: "Search:",
lengthMenu: "Show _MENU_ entries",
info: "Showing _START_ to _END_ of _TOTAL_ entries",
paginate: {
first: "First",
last: "Last",
next: "Next",
previous: "Previous"
}
}
});
```
### Server-Side Processing
```javascript
new DataTable('#serverTable', {
processing: true,
serverSide: true,
ajax: {
url: '/api/data',
type: 'POST',
data: function(d) {
// Add custom parameters
d.customParam = 'value';
}
},
columns: [
{ data: 'name' },
{ data: 'email' },
{ data: 'status' },
{
data: 'id',
render: function(data) {
return `
`;
}
}
]
});
```
## Table Patterns
### Table with Actions
```html
```
### Expandable Rows
```html
|
Order #1234 |
$150.00 |
Completed |
Order Details
Additional information about the order...
|
```
### Editable Table
```html
| Product |
Price |
Quantity |
Total |
| Product Name |
10.00 |
1 |
10.00 |
```
## Advanced Features
### Export Buttons
```javascript
new DataTable('#exportTable', {
dom: 'Bfrtip',
buttons: [
'copy',
'csv',
'excel',
'pdf',
{
extend: 'print',
text: ' Print',
className: 'btn btn-secondary'
}
]
});
```
### Column Visibility
```javascript
new DataTable('#columnToggleTable', {
dom: 'Bfrtip',
buttons: [
{
extend: 'colvis',
text: 'Columns',
className: 'btn btn-secondary'
}
],
columnDefs: [
{
targets: [2, 3],
visible: false
}
]
});
```
### Custom Filtering
```html
```
## Table Styling
### Custom Table Styles
```scss
// Compact table
.table-compact {
td, th {
padding: 0.5rem;
font-size: 0.875rem;
}
}
// Fixed header
.table-fixed-header {
thead {
position: sticky;
top: 0;
background-color: $white;
z-index: 10;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}
}
// Highlight on hover
.table-highlight tbody tr:hover {
background-color: rgba($primary, 0.05);
cursor: pointer;
}
```
## Performance Optimization
### Virtual Scrolling
```javascript
new DataTable('#largeTable', {
scrollY: '400px',
scrollCollapse: true,
scroller: true,
deferRender: true,
ajax: 'large-dataset.json'
});
```
### Lazy Loading
```javascript
let page = 1;
const pageSize = 50;
function loadMoreRows() {
fetch(`/api/data?page=${page}&size=${pageSize}`)
.then(response => response.json())
.then(data => {
const tbody = document.querySelector('#infiniteTable tbody');
data.forEach(row => {
tbody.insertAdjacentHTML('beforeend', createTableRow(row));
});
page++;
});
}
// Intersection Observer for infinite scroll
const observer = new IntersectionObserver(entries => {
if (entries[0].isIntersecting) {
loadMoreRows();
}
});
observer.observe(document.querySelector('#loadMoreTrigger'));
```
## Accessibility
- Use proper table structure with thead, tbody
- Include scope attributes on th elements
- Provide table captions when needed
- Ensure keyboard navigation works
- Use aria-label for action buttons
- Maintain focus management
## Best Practices
### DO:
- Use semantic HTML table elements
- Make tables responsive
- Provide sorting/filtering for large datasets
- Include loading states
- Show empty states when no data
- Use appropriate column widths
### DON'T:
- Don't use tables for layout
- Don't load thousands of rows at once
- Don't forget mobile experience
- Don't make cells too cramped
- Don't use tables for simple lists