inset_tables
is a npm module that replicates much of the functionality found within the jQuery DataTables FixedColumns Extension available at datatables.net.
On initialization, inset_tables
will create another <table>
element ( referred to as the overlay/inset table ) that positions itself over the base table. Additionally, a minimap
is created that allows you to scroll through hidden columns. The overlay/inset table will respond to DataTable
events such as search.dt
, order.dt
, length.dt
, page.dt
, click.dt
, etc. It also plays nicely with the Select Extension from datatables.net.
- Download
inset_tables
from npm.
npm install inset_tables
- Pass your
jQuery
instance into theinset_tables
constructor, which will returnjQuery
with the newinset_tables
plugin available on theDataTables
API.
import jQuery from "jquery";
import insetTables from "inset_tables";
var $ = jQuery;
$ = insetTables( $ );
- Initialize your
DataTable
, making sure to pass in the optionscrollX: true
, and call theinset_tables
function using the API of your newly-initializedDataTable
.
var testTable = $( "#tester-table" ).dataTable( {
"scrollX": true,
"inset": 3,
"autoWidth": true,
"data": data,
"columns": columns
} );
testTable.api().createInsetTable();
- You must pass in
scrollX: true
for this plugin to work. - You must initialize your
DataTable
withdata
andcolumns
options, instead of hardcoding table cells and columns. This is because in order to generate the overlay/inset table the base table data and columns must be available throughtable.api().init()
, which is not possible with hardcoded data. - By default,
inset_tables
will fix two( 2 ) columns. You can modify this by passing aninset
option to the.dataTable()
constructor. Theinset
option must be greater than zero( 0 ). - Pass in the
autoWidth: true
option if you would like the overlay/inset table andminimap
to be resize responsively when the browser width changes.autoWidth: true
allows thecolumn-sizing.dt
to fire on resize, which this API listens for. In some casesautoWidth: true
leads to the base table rendering strangely. If this is the case, manually hard code the table width:<table width="100%"/>
.