Gathering detailed insights and metrics for tablesorter-pagercontrols
Gathering detailed insights and metrics for tablesorter-pagercontrols
npm install tablesorter-pagercontrols
Typescript
Module System
Node Version
NPM Version
72.5
Supply Chain
84.3
Quality
75.9
Maintenance
100
Vulnerability
100
License
Total Downloads
14,777
Last Day
1
Last Week
19
Last Month
91
Last Year
2,045
Minified
Minified + Gzipped
Latest Version
1.6.0
Package Id
tablesorter-pagercontrols@1.6.0
Unpacked Size
2.49 MB
Size
281.65 kB
File Count
55
NPM Version
8.19.2
Node Version
18.12.1
Publised On
25 Sept 2023
Cumulative downloads
Total Downloads
Last day
-94.1%
1
Compared to previous day
Last week
-56.8%
19
Compared to previous week
Last month
-40.9%
91
Compared to previous month
Last year
77.5%
2,045
Compared to previous year
2
This jQuery plug-in is an add-on for mottie's tablesorter plug-in, more explicitly its pager add-on. It programmatically adds pager controls below a table and applies the pager add-on for large HTML tables, so that you don't have to insert the controls to the HTML manually any more.
V1.6 (Sept. 2023):
buttonLabelClass
,flipLeft
and rotateLeft
to default CSS which both can be used as values for the new buttonLabelClass
option if the button label for the left buttons (first and prev) are in fact right-pointing arrows of some kind,triangleIcons
to use the same right-pointing arrow icon for all button labels and flip the left buttons using the aforementioned options and class.V1.5 (Sept. 2023): Introduced the additional options forcePager
and pagerOptions
, see default options below. These were mainly added in order to support Ajax-based Pagers.
The “normal” usage of the tablesorter's pager add-on requires you to manually create a user interface (control buttons to skip pages, page size selection and page display) in your HTML document (in addition to the table). The following HTML fragment is taken from an original example page:
1<table class="tablesorter"> 2<!-- view page source to see the entire table --> 3</table> 4 5<!-- pager --> 6<div id="pager" class="pager"> 7 <form> 8 <img src="first.png" class="first"/> 9 <img src="prev.png" class="prev"/> 10 <!-- the "pagedisplay" can be any element, including an input --> 11 <span class="pagedisplay" data-pager-output-filtered="{startRow:input} – {endRow} / {filteredRows} of {totalRows} total rows"></span> 12 <img src="next.png" class="next"/> 13 <img src="last.png" class="last"/> 14 <select class="pagesize"> 15 <option value="10">10</option> 16 <option value="20">20</option> 17 <option value="30">30</option> 18 <option value="40">40</option> 19 <option value="all">All Rows</option> 20 </select> 21 </form> 22</div>
When calling the tablesorterPager
plug-in, you may then “connect” these controls with the pager by setting corresponding options to the classes of the controls. This way, the plug-in is “wired” to your controls and adds the application logic to your UI.
While that is a clear separation of logic (in javascript) and user interface (in HTML) and offers you great freedom of UI design, I personally was looking for a solution which (just like the main tablesorter
functionality) is directly applicable to any table in my web application's output without requiring the web app itself to include controls into its output.
So, the goal of this plug-in is to get rid of pager-specific HTML mark-up in the document. If you, too, want to dynamically apply a table sorter and pager to one or more tables inside some HTML document via JavaScript, while the HTML really only holds the data table, have a look at this plug-in.
Instead of manually adding controls like those shown above to your HTML document and calling the tablesorterPager
plug-in, you simply call this appendTablesorterPagerControls
plug-in on your jQuery resultset. It automatically appends a div
element beneath the table holding the default controls and then internally applies the tablesorterPager
, ‘wiring’ it to the inserted controls.
forcePager: true
, if you want to insert the pager regardless of the table size. This is especially useful if you insert an empty table and want it to be filled by partial data via Ajax requests (which is am optional feature of the Tablesorter Pager Plug-in).<button>…</button>
elements).
pillbuttons.css
stylesheet demonstrating styling capabilities by creating flat buttons with hover effect shaped with semicircles on the left- and righthand side.title
attribute).
outputFiltered
to work. If you don't use the filter widget or you don't need a different page display for filtered tables, this should also be compatible with earlier versions of tablesorter.Include the script files for jQuery, tablesorter, the pager and this plug-in to your HTML as well as the desired CSS files (you may use the bundled style sheets or create your own).
Select your tables via jQuery and apply the tablesorter
and appendTablesorterPagerControls
(instead of tablesorterPager
) to the result set.
Your HTML's head might look like this:
1<!DOCTYPE html> 2<html> 3<head> 4 <title>…</title> 5 <meta charset="utf-8"> 6 <link rel="stylesheet" href="node_modules/tablesorter/dist/css/theme.blue.css" type="text/css"> 7 8 <script type="text/javascript" src="node_modules/jquery/dist/jquery.js"></script> 9 <script type="text/javascript" src="node_modules/tablesorter/dist/js/jquery.tablesorter.min.js"></script> 10 <script type="text/javascript" src="node_modules/tablesorter/dist/js/extras/jquery.tablesorter.pager.min.js"></script> 11 <script type="text/javascript" src="js/jquery.tablesorter.pager.appendcontrols.english.min.js"></script> 12 <link rel="stylesheet" href="css/jquery.tablesorter.pager.appendcontrols.css" type="text/css"> 13 14 <script type="text/javascript"> 15 $(function() { 16 $("table") 17 .tablesorter({widthFixed: true, widgets: ['zebra']}) 18 .appendTablesorterPagerControls(); 19 }); 20 </script> 21</head>
The minified (distribution) script files include the main plug-in code as well as the tooltip definitions in one language. Therefore you'll find the script file in different versions, named after the tooltip language.
If you want to include the unminified source scripts (e.g. for debugging purposes or if you've created a new language file and not yet compiled a new distribution file using it), you'll have to first load the main script file (jquery.tablesorter.pager.appendcontrols.js
) followed by the various other files like defaults.js
and lastly the language pack file (e.g. jquery.tablesorter.pager.appendcontrols.english.js
).
The appendTablesorterPagerControls()
method optionally takes one or more objects as arguments which each may override default options. This means:
The default options are defined as follows (and may also be globally overwritten):
1$.fn.appendTablesorterPagerControls.defaults = { 2 /** 3 * The table sizes (number of visible rows) selectable by the user. 4 * Array of numbers, must be sorted (ascending) and not empty. 5 */ 6 sizes: [20, 30, 40, 50, 100], 7 /** 8 * Initial table size. 9 * This must be a single element (number) of the sizes array to be preselected 10 * when loading the page / applying the plug-ing. 11 */ 12 initialSize: 20, 13 /** 14 * Prefix string used for generated element IDs. 15 * The ID for the DIV element holding the pager controls will consist of this prefix plus a number. 16 * Form elements within that DIV will get an ID starting identically, but with a further suffix: 17 * "sel" for the table size select box and "pgnr" for the input with the page number display. 18 */ 19 prefix: "tableSorterPager", 20 /** 21 * Pattern for the arrangement of the control elements. 22 * {first}, {prev}, {next}, and {last} are placeholders for the navigation buttons, 23 * {size} will be replaced with the select box for selecting the number of visible rows, 24 * {display} stands for the status display as formatted with the output option. 25 */ 26 controlsOutput: '{first}{prev}{display}{next}{last}{size}', 27 /** 28 * This output option is passed directly to the tablesorter pager plug-in. 29 * Defines the pattern of information to be displayed in the page display. 30 * (For details see the pager documentation.) 31 * Please note, that if you change this pattern, it's recommended to also change the 32 * corresponding tooltip text (see language-specific files). 33 */ 34 output: '{page}/{totalPages} ({startRow}-{endRow}/{totalRows})', 35 /** 36 * second output pattern only used when the 'filter' widget is applied to the table and the user 37 * entered a filter, i.e. the table does not show all rows. 38 * If null, the output pattern will not change for filtered tables. But you may use this option 39 * to define a separate output pattern containing the {filteredRows} or {filteredPages} placeholders. 40 */ 41 outputFiltered: null, 42 /** 43 * Size (width) for the input holding the page display. You may change this option 44 * corresponding to the output option. 45 * Or set to 0 or null in order to disable the input field completely and render the display 46 * as styleable text (in a span field). 47 */ 48 pagedisplayInputSize: null, 49 /** 50 * CSS class for the 'next page' button, defaults to 'next'. 51 */ 52 classNext: "next", 53 /** 54 * CSS class for the 'previous page' button, defaults to 'prev'. 55 */ 56 classPrev: "prev", 57 /** 58 * CSS class for the 'first page' button, defaults to 'first'. 59 */ 60 classFirst: "first", 61 /** 62 * CSS class for the 'last page' button, defaults to 'last'. 63 */ 64 classLast: "last", 65 /** 66 * CSS class for the span or input for displaying the current page, page count etc. (see output option for formatting this display). 67 * Defaults to 'pagedisplay'. 68 * NOTE: If you change this value, the included CSS files will not work completely, but will have to be adapted to the new class name. 69 */ 70 classPagedisplay: "pagedisplay", 71 /** 72 * CSS class for the page size selection (select element, defaults to 'pagesize'). 73 */ 74 classPagesize: "pagesize", 75 /** 76 * CSS class for a div element wrapped around the table and its pager controls. 77 * Defaults to 'tablesorterPagerWrapper'. 78 * May also be space-separated list of class names like in any class attribute of an HTML element. 79 */ 80 classWrapper: "tablesorterPagerWrapper", 81 /** 82 * CSS class for a div element wrapped around the table and its pager controls within the 83 * wrapper of class 'classWrapper'. Defaults to null, in which case no inner wrapper is added. 84 * If non-null, the table and its conrols will be wrapped doubly like: 85 * <div class='classWrapper'><div class='classInnerWrapper'><table>...</table><div class='classControls'>...</div></div></div>. 86 * By default, this inner div won't be added, but it can be used for some CSS tricks: So the outer wrapper 87 * may be displayed as a block while the inner's display style may be set to 'inline-block' which 88 * allows for example to align the controls to the right with the table even if the table is not full-width. 89 * May also be space-separated list of class names like in any class attribute of an HTML element. 90 */ 91 classInnerWrapper: null, 92 /** 93 * CSS class for a div element wrapped around the table only (inside the optional innerWrapper). 94 * Defaults to null, in which case no such table wrapper is added. 95 * If non-null, the table will be wrapped like this: 96 * <div class='classWrapper'><div class='classTableWrapper'><table>...</table></div><div class='classControls'>...</div></div>. 97 * Or, if the classInnerWrapper is also non-null: 98 * <div class='classWrapper'><div class='classInnerWrapper'><div class='classTableWrapper'><table>...</table></div><div class='classControls'>...</div></div></div>. 99 * So, by default this table wrapper won't be added, but it may be added for some CSS formatting. 100 * It's especially useful if you may have very wide table and want them to be horizontally scrollable. 101 * In this case, you may set this option and introduce a CSS rule setting overflow-x: scroll for the table wrapper. 102 * That way, the table itself will be scrollable (if wider that the viewport) while the table pager controls beneath 103 * it (as well as content above the table or beneath the pager controls) will stay fixed and won't scroll left or right 104 * with the table, i.e. the user will always see and will always be able to operate the pager regardless of 105 * the horizontal scroll position of the table. 106 */ 107 classTableWrapper: null, 108 /** 109 * CSS class for a div element containing the table pager controls (inserted below the table). 110 * Defaults to 'tablesorterPagerControls'. 111 * NOTE: If you change this value, the included CSS files will not work completely, but will have to be adapted to the new class name. 112 */ 113 classControls: "tablesorterPagerControls", 114 /** 115 * button label for the 'first page' button. 116 */ 117 labelFirst: "<<", 118 /** 119 * button label for the 'previous page' button. 120 */ 121 labelPrev: "<", 122 /** 123 * button label for the 'next page' button. 124 */ 125 labelNext: ">", 126 /** 127 * button label for the 'last page' button. 128 */ 129 labelLast: ">>", 130 /** 131 * If this is a string, each button label will be wrapped in a span with a class attribute, and this property defines 132 * the latter's value. 133 * This may e.g. be used to add the class "flipLeft" to each button label. The default CSS will then horizontally flip 134 * these button labels for the left two buttons (prev and first). 135 * Alternatively, you may use the class "rotateLeft", which will by default rotate the button labels of the prev- and first- 136 * buttons by 180 degrees. 137 */ 138 buttonLabelClass: null, 139 /** 140 * If false, pager buttons are only added to a table if that table contains more rows than 141 * the smallest page size (i.e. actual row count < sizes[0]). 142 * Set this to true to force appending pager controls regardless of actual table size (e.g. if the 143 * table is still empty and will be populated via ajax requests). 144 */ 145 forcePager: false, 146 /** 147 * Any properties of this object will be passed directly to the original tablesorterPager plugin. 148 * This is empty by default, as usually all needed pager options are automatically generated by this plug-in. 149 * May be used, e.g., to add ajax options (ajaxUrl, ajaxProcessing, etc.). 150 */ 151 pagerOptions: {} 152};
As you can see in the example call above, you don't apply the tablesorter's pager plug-in directly, but you only apply the tablesorter()
plug-in method, followed directly by the appendTablesorterPagerControls()
call. The latter will apply the tablesorterPager()
-call automatically for you. The options to this tablesorterPager()
are calculated by this plug-in.
There might be situations where you want to specify your own options to pass to tablesorterPager()
, like e.g. several of the ajax*
properties which enable getting pages of table rows via Ajax calls from a server. You can now do so by collecting these in the pagerOptions
property. Such a call would thus look something like this:
1$("table") 2 .tablesorter({ 3 … options for tablesorter … 4 }) 5 .appendTablesorterPagerControls({ 6 … options for appendTablesorterPagerControls … 7 pagerOptions: { 8 … additional options for tablesorterPager … 9 (besides those automatically calculated) 10 } 11 });
As said, you may call the jQuery plug-in with an object as argument holding those options you wish to override. If you want to repeatedly override a whole subset of options, you may aggregate these into template objects. Four predefined templates are included, see templates.js.
The application of these templates is demonstrated in the examples.
If you download the package from GitHub or NPM, you'll find it includes some example pages.
Online views of these examples can also be found on the project's home page.
Copyright (c) 2023, Immo Schulz-Gerlach, www.isg-software.de
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
No vulnerabilities found.
No security vulnerabilities found.