1.0.0 • Published 8 years ago
inset_tables v1.0.0
Fixed Columns for DataTables
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.
Getting Started
- Download
inset_tablesfrom npm.
npm install inset_tables- Pass your
jQueryinstance into theinset_tablesconstructor, which will returnjQuerywith the newinset_tablesplugin available on theDataTablesAPI.
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_tablesfunction 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();Please note
- You must pass in
scrollX: truefor this plugin to work. - You must initialize your
DataTablewithdataandcolumnsoptions, 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_tableswill fix two( 2 ) columns. You can modify this by passing aninsetoption to the.dataTable()constructor. Theinsetoption must be greater than zero( 0 ). - Pass in the
autoWidth: trueoption if you would like the overlay/inset table andminimapto be resize responsively when the browser width changes.autoWidth: trueallows thecolumn-sizing.dtto fire on resize, which this API listens for. In some casesautoWidth: trueleads to the base table rendering strangely. If this is the case, manually hard code the table width:<table width="100%"/>.
1.0.0
8 years ago