1.1.6 • Published 4 months ago

herotable v1.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Herotable

Herotable is a plug-in for the jQuery Javascript library, to make your tables have the ability to filter, sort and hide and a lot of another features.

Demo

Herotable Screenshot

Installing

npm install herotable

From CDN :

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/herotable@latest/dist/css/main.min.css">
<script src="https://cdn.jsdelivr.net/npm/herotable@latest/dist/js/index.js"></script>

Note:

You must import the jquery plugin before the herotable.

Usage

$('table').herotable();

with options :

$('table').herotable({
    // options
});

Available options:

NameDescription
isRTLIf the table is in RTL direction, make it rtl in herotable, Boolean (default: false)
GeneralSearchShow the general search input above the table, Boolean (default: false)
scrollableWrapperMake the table scrollable, Boolean (default: false)
columnSearchEnable searching on each column, Boolean (default: true)
columnResizerEnable resizing feature on columns, Boolean (default: true)
hideColumnEnalbe the hide column feature, Boolean (default: true)
noAvailableDataWhen the table is empty, would you like to show the empty row or not, Boolean (default: true)
afterResizeCallbackYou can call your callback function after column resizing, there is passed parameter to function is data contains on (new_width and col_index), function (default: null)
afterHideCallbackYou can call your callback function after column hiding, function (default: null)
afterShowHiddenColsCallbackYou can call your callback function after show the hidden columns, function (default: null)
hideFooterIfBodyEmptyYou can hide the footer when you search on something and the no results, Boolean (default: true)
columnsFrom columns option you can edit the column width and column visibility at the begining, Object (default: {sizes: {}, hidden: [], types: []})
enableSumValuesOnColumnsYou can enable sum values on columns and put the summation in footer, Array(default: [])
sumValuesCellWhen you enable the summation on column, the summation will be displayed in td tag in the same index in footer, but you can determine nested element inside td, string (default: 'td')
decimalNumberLengthIf you enabled the summation on columns, you can make the summation with decimal like: 50.016 through define the length, Number(default: 0)
withPaginationFor enable the pagination feature, you must make the value is true, Boolean(default: false)
rowsPerPageIf you enabled the pagination feature, you maybe would like to change the rows count per page, Number(default: 15)
langChange the default text on elements, like (generalSearch, noAvailableData, showHiddenColumn, nextPaginateBtn, prevPaginateBtn, all)
dateFormatFuncThe default format for date columns is ISO 8601, the date that you added in the table cells will passed to new Date() method automatically, but if you want a custom date format, use dateFormatFunc and return a timestamp value.
preserveStatePreserve the state in the search inputs when return back to the page. Boolean(default: true)

Example:

$('table').herotable({
    afterHideCallback: function(data) {
        console.log(`Column index is: ${data.col_index}`);
        console.log(`New width is: ${data.new_width}`);
    },
    lang: {
        generalSearch: "Search on products",
    }
});

Another Example:

$('table').herotable({
    columns: {
        sizes: {0: 100, 1: 50}, // first column will take "100px", and the second "50px"
        hidden: [2, 3], // hide the third and fourth columns
    },
});

For a scrollableWrapper optionm you can determine the max height of the wrapper in your css :

.scrollable-herotable-wrapper {
    max-height: 350px !important;  /* default is 50vh */
}

Date Format :

// you can use any date library you want, we'll use moment.js as an example.
<script src="//momentjs.com/downloads/moment-with-locales.js"></script>

$('table').herotable({
    dateFormatFunc: function(date) {
        // If we show the dates in table by this format (DD/MM/YYYY), so
        // we'll parse it to timestamp like that through moment.js
        return +moment(date, 'DD/MM/YYYY');
    }
});

Columns Types : There are an automatically types detector for columns, and you can also define the columns types manually like that:

$('table').herotable({
    // available types: number - string - date
    columns: {
        types: ['number', 'number', 'string', 'date'],
    }
});

If you would like to destroy the herotable :

let instance = $('table').herotable();
instance[0].herotable.destroy();

Sometimes you would like to initialize the herotable in a global place, so you don't have the instance direcly, you can do this:

$('#table-id').herotable(); // in a global place

$('#table-id')[0].herotable.destroy();

And you can pass the destroy argument to herotable directly like this:

$('#table-id').herotable('destroy');
1.1.6

4 months ago

1.1.5

5 months ago

1.1.4

6 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago