Notes
โ๏ธ DataTables Key Extensions (Quick Reference)
๐ KeyTable
-
Navigate/select individual table cells (Excel-style).
Great for keyboard-based data entry.
๐ AutoFill
- Drag to duplicate or increment data like spreadsheets.
๐งพ Buttons
Built-in buttons for export & copy:
- ๐ง
copyโ Copy to clipboard - ๐
csvโ Export to CSV - ๐
excelโ Export to XLSX (requires JSZip) - ๐
pdfโ Export to PDF (requires PDFMake) - ๐จ๏ธ
printโ Print table
๐ก HTML5 Variants:
copyHtml5, csvHtml5, excelHtml5, pdfHtml5
(Use generic ones; they auto-detect browser capabilities.)
Custom Buttons:
-
text:label text -
action:function to execute on click
Example: Add your own โReloadโ or โSyncโ button.
๐๏ธโ๐จ๏ธ Column Visibility (colvis)
- Toggle visibility of single or grouped columns.
- Makes tables user-customizable and tidy.
๐งญ ColReorder
- Drag & drop to reorder columns freely.
๐งฐ ColumnControl
- Adds per-column search/sort/filter controls in headers/footers.
- Extendable with plugins for custom inputs.
โก Server-Side Processing (serverSide: true)
- For large datasets (100k+ rows) โ loads only visible data via AJAX.
- Client sends filters/paging/sorting state to server โ server returns relevant rows.
Essential for performance-heavy dashboards.
โ๏ธ Editor (CRUD made easy)
Powerful inline data editing tool:
- ๐งโโ๏ธ Full Row Editing: Modal form for entire row
- ๐ฌ Bubble Editing: Quick popup for specific cells
-
โก Inline Editing: Click โ Type โ Enter (super fast)
๐ Use generator: editor.datatables.net/generator
๐ FixedColumns
- Keep left/right columns visible while horizontally scrolling (
scrollX: true).
For non-scrollable tables, use FixedHeader.
๐ FixedHeader
- Sticky headers/footers for long tables.
- Keeps column labels visible during scroll.
๐ฑ Responsive
- Adapts layout for smaller screens.
- Hides non-essential columns, adds expandable rows.
Crucial for mobile/tablet optimization.
๐ฅ RowGroup
- Group rows by a specific column value (like categories).
- Customize group headers and footers.
โ ๏ธ Limitations:
- No expand/collapse
- Only single-level grouping
- Not compatible with Scroller or Buttons exports yet
โ๏ธ RowReorder
- Drag-and-drop rows to reorder.
- Works even with non-sequential data.
- Can sync changes with Editor for DB updates.
๐ Scroller
- Virtual rendering for huge datasets.
- Renders only visible rows (smooth scrolling, fast performance).
For millions of records, this is a must.
๐ SearchBuilder
- Build complex โAND / ORโ search queries visually.
- Auto-detects column data types and filters accordingly.
- Extendable for custom logic.
๐ SearchPanes
- Add filter panes for quick visual filtering.
- Multi-pane, multi-value searches.
Easier for users than typing queries manually.
โ Select
- Enables selection of rows, columns, or cells.
- Selection modes:
-
os(Windows-like: Ctrl + click, Shift + click) -
single,multi,multi+shift
-
- Full API:
rows().select(),cells().select(), etc. - Integrates with Buttons for โSelect all / Deselect allโ.
๐พ StateRestore
- Save & reload multiple DataTable states (filters, layout, pages).
- Store locally or via AJAX for user sessions.
๐๏ธ DateTime
- Built-in date/time picker (used by Editor & SearchBuilder).
- Integrates with Moment.js, Luxon, or Day.js.
$('#myTable').DataTable( {
keys: true,
autoFill: true,
colReorder: true,
fixedColumns: true,
fixedHeader: true,
responsive: true,
rowReorder: true,
ajax: '/api/data',
scrollY: 200,
deferRender: true,
scroller: true,
select: true,
columnControl: ['order', ['orderAsc', 'orderDesc', 'search']],
buttons: [
{
extend: 'pdfHtml5',
title: '<?= $heading; ?>',
text: 'PDF',
titleAttr: 'Generate PDF',
className: 'btn-outline-danger btn-sm mr-1',
exportOptions: {
columns: ':visible'
} // to download only visible columsn using colvis
},
{
extend: 'excelHtml5',
title: '<?= $heading; ?>',
text: 'Excel',
titleAttr: 'Generate Excel',
className: 'btn-outline-success btn-sm mr-1'
},
{
extend: 'csvHtml5',
title: '<?= $heading; ?>',
text: 'CSV',
titleAttr: 'Generate CSV',
className: 'btn-outline-primary btn-sm mr-1'
},
{
extend: 'copyHtml5',
title: '<?= $heading; ?>',
text: 'Copy',
titleAttr: 'Copy to clipboard',
className: 'btn-outline-primary btn-sm mr-1'
},
{
extend: 'colvis',
title: '<?= $heading; ?>',
text: 'colvis',
titleAttr: 'select columns',
className: 'btn-outline-primary btn-sm mr-1'
},
{
extend: 'print',
text: 'Print',
titleAttr: 'Print Table',
title: '<?= $heading; ?>',
customize: function (win) {
$(win.document.body).find('h1').css('text-align', 'center');
$(win.document.body).css('font-size', '9px');
$(win.document.body).find('table')
.addClass('compact')
.css('font-size', 'inherit');
},
className: 'btn-outline-primary btn-sm'
},
//custom button
{
text: 'Reload',
action: function ( e, dt, node, config ) {
dt.ajax.reload();
}
],
rowGroup: {
dataSrc: 'group'
},
} );
``
Top comments (0)