patternfly-sass 3.13.0 → 3.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/javascripts/patternfly-functions.js +1137 -0
- data/assets/javascripts/patternfly-functions.min.js +1 -0
- data/assets/javascripts/patternfly-settings.js +506 -0
- data/assets/javascripts/patternfly-settings.min.js +1 -0
- data/assets/javascripts/patternfly.dataTables.pfEmpty.js +244 -0
- data/assets/javascripts/patternfly.dataTables.pfEmpty.min.js +1 -0
- data/assets/javascripts/patternfly.dataTables.pfFilter.js +421 -0
- data/assets/javascripts/patternfly.dataTables.pfFilter.min.js +1 -0
- data/assets/javascripts/patternfly.dataTables.pfResize.js +214 -0
- data/assets/javascripts/patternfly.dataTables.pfResize.min.js +1 -0
- data/assets/javascripts/patternfly.dataTables.pfSelect.js +281 -0
- data/assets/javascripts/patternfly.dataTables.pfSelect.min.js +1 -0
- data/assets/javascripts/patternfly.js +692 -652
- data/assets/javascripts/patternfly.min.js +2 -2
- data/assets/stylesheets/_patternfly.scss +1 -0
- data/assets/stylesheets/patternfly/_datatables.scss +17 -49
- data/assets/stylesheets/patternfly/_table-view.scss +170 -0
- data/bower.json +1 -1
- data/lib/patternfly-sass/version.rb +2 -2
- data/package.json +70 -0
- data/spec/html/about-modal.html +1 -0
- data/spec/html/accordions.html +1 -0
- data/spec/html/alerts.html +1 -0
- data/spec/html/area-charts.html +1 -0
- data/spec/html/badges.html +1 -0
- data/spec/html/bar-charts.html +1 -0
- data/spec/html/basic.html +368 -418
- data/spec/html/blank-slate.html +2 -1
- data/spec/html/bootstrap-combobox.html +1 -0
- data/spec/html/bootstrap-datepicker.html +1 -0
- data/spec/html/bootstrap-select.html +1 -0
- data/spec/html/bootstrap-switch.html +1 -0
- data/spec/html/bootstrap-touchspin.html +1 -0
- data/spec/html/bootstrap-treeview-2.html +1 -0
- data/spec/html/bootstrap-treeview.html +1 -0
- data/spec/html/breadcrumbs.html +1 -0
- data/spec/html/buttons.html +1 -0
- data/spec/html/card-view-card-variations.html +1 -0
- data/spec/html/card-view-multi-select.html +1 -0
- data/spec/html/card-view-single-select.html +1 -0
- data/spec/html/cards.html +1 -0
- data/spec/html/code.html +1 -0
- data/spec/html/dashboard.html +1 -0
- data/spec/html/dist/css/patternfly-additions.css +143 -52
- data/spec/html/dist/css/patternfly-additions.css.map +1 -1
- data/spec/html/dist/css/patternfly-additions.min.css +1 -1
- data/spec/html/dist/css/patternfly-additions.min.css.map +1 -1
- data/spec/html/dist/css/patternfly.min.css +2 -2
- data/spec/html/dist/css/patternfly.min.css.map +1 -1
- data/spec/html/donut-charts.html +1 -0
- data/spec/html/dropdowns.html +1 -0
- data/spec/html/form.html +1 -0
- data/spec/html/forms.html +1 -0
- data/spec/html/horizontal-navigation.html +1 -0
- data/spec/html/icons.html +1 -0
- data/spec/html/index.html +10 -6
- data/spec/html/infotip.html +1 -0
- data/spec/html/labels.html +1 -0
- data/spec/html/line-charts.html +1 -0
- data/spec/html/list-group.html +1 -0
- data/spec/html/list-view-compound-expansion.html +1 -0
- data/spec/html/list-view-rows.html +1 -0
- data/spec/html/list-view-simple-expansion.html +1 -0
- data/spec/html/list-view.html +1 -0
- data/spec/html/login.html +1 -0
- data/spec/html/modals.html +1 -0
- data/spec/html/navbar.html +1 -0
- data/spec/html/notification-drawer-horizontal-nav.html +1 -0
- data/spec/html/notification-drawer-vertical-nav.html +1 -0
- data/spec/html/pagination.html +1 -0
- data/spec/html/panels.html +1 -0
- data/spec/html/pie-charts.html +1 -0
- data/spec/html/popovers.html +1 -0
- data/spec/html/progress-bars.html +1 -0
- data/spec/html/search.html +1 -0
- data/spec/html/spinner.html +1 -0
- data/spec/html/tab.html +373 -420
- data/spec/html/{datatables-columns.html → table-view-columns.html} +9 -7
- data/spec/html/table-view-navbar.html +532 -0
- data/spec/html/table-view.html +422 -0
- data/spec/html/tables.html +1 -0
- data/spec/html/tabs.html +1 -0
- data/spec/html/time-picker.html +1 -0
- data/spec/html/toast.html +1 -0
- data/spec/html/toolbar.html +1 -0
- data/spec/html/tooltip.html +1 -0
- data/spec/html/typography-2.html +1 -1
- data/spec/html/typography.html +1 -0
- data/spec/html/utilization-bar-charts.html +1 -0
- data/spec/html/vertical-navigation-primary-only.html +1 -0
- data/spec/html/vertical-navigation-with-badges.html +1 -0
- data/spec/html/vertical-navigation-with-secondary.html +1 -0
- data/spec/html/vertical-navigation-with-tertiary-no-icons.html +1 -0
- data/spec/html/vertical-navigation-with-tertiary-pins.html +1 -0
- data/spec/html/wizard.html +1 -0
- metadata +22 -6
- data/spec/html/datatables.html +0 -472
@@ -0,0 +1 @@
|
|
1
|
+
!function(factory){"use strict";"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function($){return factory($,window,document)}):"object"==typeof exports?module.exports=function(root,$){return root||(root=window),$&&$.fn.dataTable||($=require("datatables.net")(root,$).$),factory($,root,root.document)}:factory(jQuery,window,document)}(function($,window,document,undefined){"use strict";function addActiveFilterControl(dt,filter){var i,ctx=dt.settings()[0];ctx._pfFilter.activeFilterControls.append('<li><span class="label label-info">'+filter.name+": "+filter.value+'<a href="#"><span class="pficon pficon-close"/></a></span></li>'),$("a",ctx._pfFilter.activeFilterControls).last().on("click",function(e){for(i=0;i<ctx._pfFilter.filters.length;i++)if(ctx._pfFilter.filters[i].column===filter.column&&ctx._pfFilter.filters[i].value===filter.value){ctx._pfFilter.filters.splice(i,1),$(this).parents("li").remove();break}0===ctx._pfFilter.filters.length&&ctx._pfFilter.activeFilters.addClass("hidden"),dt.draw(),updateFilterResults(dt)}),ctx._pfFilter.activeFilters.removeClass("hidden")}function addFilter(dt,filter){var ctx=dt.settings()[0],found=!1;$.grep(ctx._pfFilter.filters,function(f){f.column===filter.column&&f.value===filter.value&&(found=!0)}),found||(ctx._pfFilter.filters.push(filter),dt.draw(),addActiveFilterControl(dt,filter),updateFilterResults(dt)),ctx._pfFilter.filterInput.val("")}function clearFilters(dt){var ctx=dt.settings()[0];ctx._pfFilter.filters.length=0,ctx._pfFilter.activeFilterControls.html(""),ctx._pfFilter.activeFilters.addClass("hidden"),dt.draw()}function handleClearFilters(dt){var ctx=dt.settings()[0];ctx._pfFilter.clearFilters!==undefined&&0!==ctx._pfFilter.clearFilters.length&&ctx._pfFilter.clearFilters.on("click",function(e){clearFilters(dt)})}function handleFilterInput(dt){var ctx=dt.settings()[0];ctx._pfFilter.filterInput!==undefined&&0!==ctx._pfFilter.filterInput.length&&ctx._pfFilter.filterInput.on("keypress",function(e){var keycode=e.keyCode?e.keyCode:e.which;return 13!==keycode||(e.preventDefault(),this.value.trim().length>0&&addFilter(dt,{column:ctx._pfFilter.filterColumn,name:ctx._pfFilter.filterName,value:this.value}),!1)})}function handleFilterOption(dt,i){var ctx=dt.settings()[0];null!==ctx._pfFilter.filterCols[i]&&ctx._pfFilter.filterCols[i].optionSelector!==undefined&&$(ctx._pfFilter.filterCols[i].optionSelector).on("click",function(e){ctx._pfFilter.filterInput!==undefined&&0!==ctx._pfFilter.filterInput.length&&(ctx._pfFilter.filterInput.get(0).placeholder=ctx._pfFilter.filterCols[i].placeholder),ctx._pfFilter.filterLabel!==undefined&&0!==ctx._pfFilter.filterLabel.length&&ctx._pfFilter.filterLabel.html($(this).text()),ctx._pfFilter.filterButton!==undefined&&0!==ctx._pfFilter.filterButton.length&&ctx._pfFilter.filterButton.html($(this).text()+' <span class="caret"></span>'),ctx._pfFilter.filterColumn=i,ctx._pfFilter.filterName=$(this).text()})}function updateFilterResults(dt){var ctx=dt.settings()[0],filteredRows=dt.rows({page:"current",search:"applied"}).flatten().length;ctx._pfFilter.filterResults!==undefined&&0!==ctx._pfFilter.filterResults.length&&ctx._pfFilter.filterResults.html(filteredRows+" Results")}var DataTable=$.fn.dataTable,ACTIVE_FILTER_CONTROLS_SELECTOR=".list-inline",CLEAR_FILTERS_SELECTOR=".toolbar-pf-results a",FILTER_SELECTOR=".toolbar-pf-filter",FILTER_BUTTON_SELECTOR=FILTER_SELECTOR+" button",FILTER_INPUT_SELECTOR=FILTER_SELECTOR+" input",FILTER_LABEL_SELECTOR=FILTER_SELECTOR+" label",RESULTS_SELECTOR=".toolbar-pf-results",FILTER_RESULTS_SELECTOR=RESULTS_SELECTOR+" h5";return DataTable.pfFilter={},DataTable.pfFilter.init=function(dt){var i,ctx=dt.settings()[0],opts=ctx.oInit.pfConfig?ctx.oInit.pfConfig:{};if(ctx._pfFilter={},ctx._pfFilter.filterButton=$(FILTER_BUTTON_SELECTOR,opts.toolbarSelector),ctx._pfFilter.filterCols=opts.filterCols,ctx._pfFilter.filterLabel=$(FILTER_LABEL_SELECTOR,opts.toolbarSelector),ctx._pfFilter.filterInput=$(FILTER_INPUT_SELECTOR,opts.toolbarSelector),ctx._pfFilter.filters=[],ctx._pfFilter.activeFilterControls=$(ACTIVE_FILTER_CONTROLS_SELECTOR,opts.toolbarSelector),ctx._pfFilter.activeFilters=ctx._pfFilter.activeFilterControls.closest("div"),ctx._pfFilter.clearFilters=$(CLEAR_FILTERS_SELECTOR,opts.toolbarSelector),ctx._pfFilter.results=$(RESULTS_SELECTOR,opts.toolbarSelector),ctx._pfFilter.filterResults=$(FILTER_RESULTS_SELECTOR,opts.toolbarSelector),ctx._pfFilter.filterCols!==undefined){for(i=0;i<ctx._pfFilter.filterCols.length&&(null===ctx._pfFilter.filterCols[i]||(ctx._pfFilter.filterColumn=i,ctx._pfFilter.filterName=$(ctx._pfFilter.filterCols[i].optionSelector).text(),ctx._pfFilter.filterCols[i].default!==!0));i++);for(i=0;i<ctx._pfFilter.filterCols.length;i++)handleFilterOption(dt,i);handleFilterInput(dt),handleClearFilters(dt),$.fn.dataTable.ext.search.push(function(ctx,data,dataIndex){var showThisRow=!0;return ctx._pfFilter&&$.each(ctx._pfFilter.filters,function(index,filter){data[filter.column].indexOf(filter.value)===-1&&(showThisRow=!1)}),showThisRow})}},DataTable.Api.register("pfFilter.addFilter()",function(filter){return this.iterator("table",function(ctx){addFilter(new DataTable.Api(ctx),filter)})}),DataTable.Api.register("pfFilter.clearFilters()",function(){return this.iterator("table",function(ctx){clearFilters(new DataTable.Api(ctx))})}),$(document).on("init.dt",function(e,ctx,json){"dt"===e.namespace&&DataTable.pfFilter.init(new DataTable.Api(ctx))}),DataTable.pfFilter});
|
@@ -0,0 +1,214 @@
|
|
1
|
+
/**
|
2
|
+
* @summary pfResize for DataTables
|
3
|
+
* @description A collection of API methods providing resize functionality in DataTables. This ensures DataTables
|
4
|
+
* meets the Patternfly design pattern for IE browsers. Inline actions are typically located in the last column of
|
5
|
+
* DataTables and expected to be styled with table-view-pf-actions. Inline action buttons must also be wrapped with the
|
6
|
+
* table-view-pf-btn class.
|
7
|
+
*
|
8
|
+
* Example:
|
9
|
+
*
|
10
|
+
* <!-- NOTE: Some configuration may be omitted for clarity -->
|
11
|
+
* ...
|
12
|
+
* <table class="table table-striped table-bordered table-hover" id="table1">
|
13
|
+
* <thead>
|
14
|
+
* <tr>
|
15
|
+
* <th><input type="checkbox" name="selectAll"></th>
|
16
|
+
* <th>Rendering Engine</th>
|
17
|
+
* <th>Browser</th>
|
18
|
+
* <th colspan="2">Actions</th>
|
19
|
+
* </tr>
|
20
|
+
* </thead>
|
21
|
+
* </table>
|
22
|
+
* ...
|
23
|
+
* <script>
|
24
|
+
* // NOTE: Some properties may be omitted for clarity
|
25
|
+
* $(document).ready(function() {
|
26
|
+
* var dt = $("#table1").DataTable({
|
27
|
+
* columns: [
|
28
|
+
* { data: null, ... },
|
29
|
+
* { data: "engine" },
|
30
|
+
* { data: "browser" }
|
31
|
+
* { data: null,
|
32
|
+
* className: "table-view-pf-actions",
|
33
|
+
* render: function (data, type, full, meta) {
|
34
|
+
* // Inline action button renderer
|
35
|
+
* return '<div class="table-view-pf-btn"><button class="btn btn-default" type="button">Actions</button></div>';
|
36
|
+
* }
|
37
|
+
* }, {
|
38
|
+
* data: null,
|
39
|
+
* className: "table-view-pf-actions",
|
40
|
+
* render: function (data, type, full, meta) {
|
41
|
+
* // Inline action kebab renderer
|
42
|
+
* return '<div class="dropdown dropdown-kebab-pf">' +
|
43
|
+
* '<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">' +
|
44
|
+
* '<span class="fa fa-ellipsis-v"></span></button>' +
|
45
|
+
* '<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownKebabRight">' +
|
46
|
+
* '<li><a href="#">Action</a></li>' +
|
47
|
+
* '<li><a href="#">Another action</a></li>' +
|
48
|
+
* '<li><a href="#">Something else here</a></li>' +
|
49
|
+
* '<li role="separator" class="divider"></li>' +
|
50
|
+
* '<li><a href="#">Separated link</a></li></ul></div>';
|
51
|
+
* }
|
52
|
+
* }
|
53
|
+
* ],
|
54
|
+
* data: [
|
55
|
+
* { engine: "Gecko", browser: "Firefox" }
|
56
|
+
* { engine: "Trident", browser: "Mozilla" }
|
57
|
+
* ],
|
58
|
+
* dom: "t",
|
59
|
+
* pfConfig: {
|
60
|
+
* ...
|
61
|
+
* }
|
62
|
+
* });
|
63
|
+
* dt.table().pfResize.resize(); // Optional API to force resize
|
64
|
+
* });
|
65
|
+
* </script>
|
66
|
+
*
|
67
|
+
* Note: This functionality requires the following Javascript library files to be loaded:
|
68
|
+
*
|
69
|
+
* https://cdn.datatables.net/select/1.2.0/js/dataTables.select.min.js
|
70
|
+
*/
|
71
|
+
(function (factory) {
|
72
|
+
"use strict";
|
73
|
+
if (typeof define === "function" && define.amd ) {
|
74
|
+
// AMD
|
75
|
+
define (["jquery", "datatables.net"], function ($) {
|
76
|
+
return factory ($, window, document);
|
77
|
+
});
|
78
|
+
} else if (typeof exports === "object") {
|
79
|
+
// CommonJS
|
80
|
+
module.exports = function (root, $) {
|
81
|
+
if (!root) {
|
82
|
+
root = window;
|
83
|
+
}
|
84
|
+
if (!$ || !$.fn.dataTable) {
|
85
|
+
$ = require("datatables.net")(root, $).$;
|
86
|
+
}
|
87
|
+
return factory($, root, root.document);
|
88
|
+
};
|
89
|
+
} else {
|
90
|
+
// Browser
|
91
|
+
factory(jQuery, window, document);
|
92
|
+
}
|
93
|
+
}(function ($, window, document, undefined) {
|
94
|
+
"use strict";
|
95
|
+
var DataTable = $.fn.dataTable;
|
96
|
+
var BUTTON_ACTIONS_SELECTOR = "td.table-view-pf-actions .table-view-pf-btn";
|
97
|
+
var KEBAB_ACTIONS_SELECTOR = "td.table-view-pf-actions .dropdown";
|
98
|
+
|
99
|
+
DataTable.pfResize = {};
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Initialize
|
103
|
+
*
|
104
|
+
* @param {DataTable.Api} dt DataTable
|
105
|
+
* @private
|
106
|
+
*/
|
107
|
+
DataTable.pfResize.init = function (dt) {
|
108
|
+
var ctx = dt.settings()[0];
|
109
|
+
|
110
|
+
ctx._pfResize = {};
|
111
|
+
|
112
|
+
if (isIE()) {
|
113
|
+
// Resize buttons to fill table cells.
|
114
|
+
$(window).on("resize", function () {
|
115
|
+
resize(dt);
|
116
|
+
});
|
117
|
+
|
118
|
+
// Initialize
|
119
|
+
resize(dt);
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
// Local functions
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Get inline actions
|
127
|
+
*
|
128
|
+
* @param {DataTable.Api} dt DataTable
|
129
|
+
* @private
|
130
|
+
*/
|
131
|
+
function getActions (dt) {
|
132
|
+
return $(BUTTON_ACTIONS_SELECTOR + ", " + KEBAB_ACTIONS_SELECTOR, dt.table().container());
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Detect IE
|
137
|
+
*
|
138
|
+
* @return {boolean} True if IE is detected
|
139
|
+
* @private
|
140
|
+
*/
|
141
|
+
function isIE () {
|
142
|
+
return /(MSIE|Trident\/|Edge\/)/i.test(window.navigator.userAgent);
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Reset table cell height prior to resizing inline actions
|
147
|
+
*
|
148
|
+
* @param {DataTable.Api} dt DataTable
|
149
|
+
* @param {Object} actions Inline actions to reset height
|
150
|
+
* @private
|
151
|
+
*/
|
152
|
+
function resetTableCells (dt, actions) {
|
153
|
+
if (actions === undefined || actions.length === 0) {
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
$(actions).each(function (index, el) {
|
157
|
+
$(el).css({height: "auto"});
|
158
|
+
});
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Resize inline actions
|
163
|
+
*
|
164
|
+
* @param {DataTable.Api} dt DataTable
|
165
|
+
* @private
|
166
|
+
*/
|
167
|
+
function resize (dt) {
|
168
|
+
var actions = $(BUTTON_ACTIONS_SELECTOR + ", " + KEBAB_ACTIONS_SELECTOR, dt.table().container());
|
169
|
+
resetTableCells(dt, actions);
|
170
|
+
resizeInlineActions(dt, actions);
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Resize inline actions to fill table cells
|
175
|
+
*
|
176
|
+
* @param {DataTable.Api} dt DataTable
|
177
|
+
* @param {Object} actions Inline actions to resize
|
178
|
+
* @private
|
179
|
+
*/
|
180
|
+
function resizeInlineActions (dt, actions) {
|
181
|
+
if (actions === undefined || actions.length === 0) {
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
$(actions).each(function (index, el) {
|
185
|
+
var parent = $(el).parent("td");
|
186
|
+
if (parent === undefined || parent.length === 0) {
|
187
|
+
return;
|
188
|
+
}
|
189
|
+
$(el).css({height: parent[0].clientHeight});
|
190
|
+
});
|
191
|
+
}
|
192
|
+
|
193
|
+
// DataTables API
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Resize inline actions
|
197
|
+
*
|
198
|
+
* Example: dt.table().pfResize.resize();
|
199
|
+
*/
|
200
|
+
DataTable.Api.register("pfResize.resize()", function () {
|
201
|
+
return this.iterator("table", function (ctx) {
|
202
|
+
resize(new DataTable.Api(ctx));
|
203
|
+
});
|
204
|
+
});
|
205
|
+
|
206
|
+
// DataTables creation
|
207
|
+
$(document).on("init.dt", function (e, ctx, json) {
|
208
|
+
if (e.namespace !== "dt") {
|
209
|
+
return;
|
210
|
+
}
|
211
|
+
DataTable.pfResize.init(new DataTable.Api(ctx));
|
212
|
+
});
|
213
|
+
return DataTable.pfResize;
|
214
|
+
}));
|
@@ -0,0 +1 @@
|
|
1
|
+
!function(factory){"use strict";"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function($){return factory($,window,document)}):"object"==typeof exports?module.exports=function(root,$){return root||(root=window),$&&$.fn.dataTable||($=require("datatables.net")(root,$).$),factory($,root,root.document)}:factory(jQuery,window,document)}(function($,window,document,undefined){"use strict";function isIE(){return/(MSIE|Trident\/|Edge\/)/i.test(window.navigator.userAgent)}function resetTableCells(dt,actions){actions!==undefined&&0!==actions.length&&$(actions).each(function(index,el){$(el).css({height:"auto"})})}function resize(dt){var actions=$(BUTTON_ACTIONS_SELECTOR+", "+KEBAB_ACTIONS_SELECTOR,dt.table().container());resetTableCells(dt,actions),resizeInlineActions(dt,actions)}function resizeInlineActions(dt,actions){actions!==undefined&&0!==actions.length&&$(actions).each(function(index,el){var parent=$(el).parent("td");parent!==undefined&&0!==parent.length&&$(el).css({height:parent[0].clientHeight})})}var DataTable=$.fn.dataTable,BUTTON_ACTIONS_SELECTOR="td.table-view-pf-actions .table-view-pf-btn",KEBAB_ACTIONS_SELECTOR="td.table-view-pf-actions .dropdown";return DataTable.pfResize={},DataTable.pfResize.init=function(dt){var ctx=dt.settings()[0];ctx._pfResize={},isIE()&&($(window).on("resize",function(){resize(dt)}),resize(dt))},DataTable.Api.register("pfResize.resize()",function(){return this.iterator("table",function(ctx){resize(new DataTable.Api(ctx))})}),$(document).on("init.dt",function(e,ctx,json){"dt"===e.namespace&&DataTable.pfResize.init(new DataTable.Api(ctx))}),DataTable.pfResize});
|
@@ -0,0 +1,281 @@
|
|
1
|
+
/**
|
2
|
+
* @summary pfSelect for DataTables
|
3
|
+
* @description A collection of API methods providing individual row selection and select all functionality in
|
4
|
+
* DataTables using traditional HTML checkboxes. This ensures DataTables meets the Patternfly design pattern while
|
5
|
+
* maintaining accessibility.
|
6
|
+
*
|
7
|
+
* The following selection styles are supported for user interaction with DataTables:
|
8
|
+
*
|
9
|
+
* api - Selection can only be performed via the API
|
10
|
+
* multi - Multiple items can be selected
|
11
|
+
* multi+shift - a hybrid between the os style and multi
|
12
|
+
* os - Operating system style selection with complex behaviors such as ctrl/cmd, shift and an unmodified click
|
13
|
+
* single - Only a single item can be selected
|
14
|
+
*
|
15
|
+
* For details see: https://datatables.net/reference/option/select.style
|
16
|
+
*
|
17
|
+
* Note that when a selection is made, the selection results text is also updated in the toolbar. The toolbar layouts is
|
18
|
+
* expected to contain the classes as shown in the example below. Selection checkboxes are also expected to be located
|
19
|
+
* in the first column.
|
20
|
+
*
|
21
|
+
* Example:
|
22
|
+
*
|
23
|
+
* <!-- NOTE: Some configuration may be omitted for clarity -->
|
24
|
+
* <div class="row toolbar-pf table-view-pf-toolbar" id="toolbar1">
|
25
|
+
* <div class="col-sm-12">
|
26
|
+
* ...
|
27
|
+
* <div class="row toolbar-pf-results">
|
28
|
+
* <div class="col-sm-9">
|
29
|
+
* ...
|
30
|
+
* </div>
|
31
|
+
* <div class="col-sm-3 table-view-pf-select-results">
|
32
|
+
* <strong>0</strong> of <strong>0</strong> selected
|
33
|
+
* </div>
|
34
|
+
* </div>
|
35
|
+
* </div>
|
36
|
+
* </div>
|
37
|
+
* <table class="table table-striped table-bordered table-hover" id="table1">
|
38
|
+
* <thead>
|
39
|
+
* <tr>
|
40
|
+
* <th><input type="checkbox" name="selectAll"></th>
|
41
|
+
* <th>Rendering Engine</th>
|
42
|
+
* <th>Browser</th>
|
43
|
+
* </tr>
|
44
|
+
* </thead>
|
45
|
+
* </table>
|
46
|
+
* ...
|
47
|
+
* <script>
|
48
|
+
* // NOTE: Some properties may be omitted for clarity
|
49
|
+
* $(document).ready(function() {
|
50
|
+
* var dt = $("#table1").DataTable({
|
51
|
+
* columns: [
|
52
|
+
* { data: null,
|
53
|
+
* className: "table-view-pf-select",
|
54
|
+
* render: function (data, type, full, meta) {
|
55
|
+
* return '<input type="checkbox" name="select">';
|
56
|
+
* },
|
57
|
+
* sortable: false
|
58
|
+
* },
|
59
|
+
* { data: "engine" },
|
60
|
+
* { data: "browser" }
|
61
|
+
* ],
|
62
|
+
* data: [
|
63
|
+
* { engine: "Gecko", browser: "Firefox" }
|
64
|
+
* { engine: "Trident", browser: "Mozilla" }
|
65
|
+
* ],
|
66
|
+
* dom: "t",
|
67
|
+
* order: [[ 1, "asc" ]],
|
68
|
+
* pfConfig: {
|
69
|
+
* ...
|
70
|
+
* toolbarSelector: "#{{include.toolbarId}}",
|
71
|
+
* selectAllSelector: 'th:first-child input[type="checkbox"]'
|
72
|
+
* }
|
73
|
+
* select: {
|
74
|
+
* selector: 'td:first-child input[type="checkbox"]',
|
75
|
+
* style: "multi"
|
76
|
+
* }
|
77
|
+
* });
|
78
|
+
* dt.table().pfSelect.selectAllRows(true); // Optional API to select all rows
|
79
|
+
* });
|
80
|
+
* </script>
|
81
|
+
*
|
82
|
+
* Note: This functionality requires the following Javascript library files to be loaded:
|
83
|
+
*
|
84
|
+
* https://cdn.datatables.net/select/1.2.0/js/dataTables.select.min.js
|
85
|
+
*/
|
86
|
+
(function (factory) {
|
87
|
+
"use strict";
|
88
|
+
if (typeof define === "function" && define.amd ) {
|
89
|
+
// AMD
|
90
|
+
define (["jquery", "datatables.net"], function ($) {
|
91
|
+
return factory ($, window, document);
|
92
|
+
});
|
93
|
+
} else if (typeof exports === "object") {
|
94
|
+
// CommonJS
|
95
|
+
module.exports = function (root, $) {
|
96
|
+
if (!root) {
|
97
|
+
root = window;
|
98
|
+
}
|
99
|
+
if (!$ || !$.fn.dataTable) {
|
100
|
+
$ = require("datatables.net")(root, $).$;
|
101
|
+
}
|
102
|
+
return factory($, root, root.document);
|
103
|
+
};
|
104
|
+
} else {
|
105
|
+
// Browser
|
106
|
+
factory(jQuery, window, document);
|
107
|
+
}
|
108
|
+
}(function ($, window, document, undefined) {
|
109
|
+
"use strict";
|
110
|
+
var DataTable = $.fn.dataTable;
|
111
|
+
var RESULTS_SELECTOR = ".table-view-pf-select-results"; // Toolbar selection results
|
112
|
+
var SELECT_ALL_SELECTOR = 'th:first-child input[type="checkbox"]'; // Default checkbox for selecting all rows
|
113
|
+
var SELECT_SELECTOR = 'td:first-child input[type="checkbox"]'; // Default checkboxes for row selection
|
114
|
+
|
115
|
+
DataTable.pfSelect = {};
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Initialize
|
119
|
+
*
|
120
|
+
* @param {DataTable.Api} dt DataTable
|
121
|
+
* @private
|
122
|
+
*/
|
123
|
+
DataTable.pfSelect.init = function (dt) {
|
124
|
+
var ctx = dt.settings()[0];
|
125
|
+
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
|
126
|
+
var select = (ctx.oInit.select) ? ctx.oInit.select : {};
|
127
|
+
var style = dt.select.style();
|
128
|
+
|
129
|
+
ctx._pfSelect = {};
|
130
|
+
ctx._pfSelect.selectAllSelector = (opts.selectAllSelector !== undefined)
|
131
|
+
? opts.selectAllSelector : SELECT_ALL_SELECTOR; // Select all checkbox
|
132
|
+
ctx._pfSelect.selector = (select.selector !== undefined)
|
133
|
+
? select.selector : SELECT_SELECTOR; // Select checkbox
|
134
|
+
ctx._pfSelect.results = $(RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar selection results
|
135
|
+
|
136
|
+
if (style === "api") {
|
137
|
+
// Select all checkbox
|
138
|
+
$(dt.table().container()).on("click", ctx._pfSelect.selectAllSelector, function (evt) {
|
139
|
+
evt.preventDefault();
|
140
|
+
});
|
141
|
+
|
142
|
+
// Select checkboxes
|
143
|
+
$(dt.table().container()).on("click", ctx._pfSelect.selector, function (evt) {
|
144
|
+
evt.preventDefault();
|
145
|
+
});
|
146
|
+
|
147
|
+
dt.table().on("select.dt", function () {
|
148
|
+
syncSelectCheckboxes(dt);
|
149
|
+
});
|
150
|
+
} else {
|
151
|
+
// Select all checkbox
|
152
|
+
$(dt.table().container()).on("click", ctx._pfSelect.selectAllSelector, function (evt) {
|
153
|
+
selectAllRows(dt, evt.target.checked);
|
154
|
+
});
|
155
|
+
|
156
|
+
// Select checkboxes
|
157
|
+
$(dt.table().container()).on("click", ctx._pfSelect.selector, function (evt) {
|
158
|
+
if (style !== "multi" || style !== "multi+shift") {
|
159
|
+
syncSelectCheckboxes(dt); // No need to sync checkbox selections when "multi" is used
|
160
|
+
} else {
|
161
|
+
syncSelectAllCheckbox(dt); // Still need to sync select all checkbox
|
162
|
+
}
|
163
|
+
});
|
164
|
+
}
|
165
|
+
|
166
|
+
// Sync checkbox selections when paging and filtering is applied
|
167
|
+
dt.table().on("draw.dt", function () {
|
168
|
+
syncSelectCheckboxes(dt);
|
169
|
+
});
|
170
|
+
|
171
|
+
// Initialize selected rows text
|
172
|
+
updateSelectedRowsText(dt);
|
173
|
+
};
|
174
|
+
|
175
|
+
// Local functions
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Select all rows on current page
|
179
|
+
*
|
180
|
+
* @param {DataTable.Api} dt DataTable
|
181
|
+
* @param {boolean} select True to select all rows on current page, defaults to false
|
182
|
+
* @private
|
183
|
+
*/
|
184
|
+
function selectAllRows (dt, select) {
|
185
|
+
var ctx = dt.settings()[0];
|
186
|
+
|
187
|
+
// Retrieve all rows taking into account currently applied filter
|
188
|
+
var filteredRows = dt.rows({"page": "current", "search": "applied"});
|
189
|
+
|
190
|
+
// Check if style is single
|
191
|
+
if (dt.select.style() === "single") {
|
192
|
+
throw new Error("Cannot select all rows with selection style 'single'");
|
193
|
+
}
|
194
|
+
|
195
|
+
// Select rows
|
196
|
+
if (select) {
|
197
|
+
filteredRows.select();
|
198
|
+
} else {
|
199
|
+
filteredRows.deselect();
|
200
|
+
}
|
201
|
+
$(ctx._pfSelect.selector, dt.table().container()).prop("checked", select); // De/select checkboxes in view
|
202
|
+
syncSelectAllCheckbox(dt);
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* Sync select all checkbox with row selections on current page
|
207
|
+
*
|
208
|
+
* @param {DataTable.Api} dt DataTable
|
209
|
+
* @private
|
210
|
+
*/
|
211
|
+
function syncSelectAllCheckbox (dt) {
|
212
|
+
var ctx = dt.settings()[0];
|
213
|
+
|
214
|
+
// Retrieve all rows taking into account currently applied filter
|
215
|
+
var filteredRows = dt.rows({"page": "current", "search": "applied"}).flatten().length;
|
216
|
+
var selectedFilteredRows = dt.rows({"page": "current", "search": "applied", "selected": true}).flatten().length;
|
217
|
+
|
218
|
+
// De/select the select all checkbox
|
219
|
+
var selectAll = $(ctx._pfSelect.selectAllSelector, dt.table().container())[0];
|
220
|
+
if (selectAll) {
|
221
|
+
selectAll.checked = (filteredRows === selectedFilteredRows);
|
222
|
+
}
|
223
|
+
updateSelectedRowsText(dt);
|
224
|
+
}
|
225
|
+
|
226
|
+
/**
|
227
|
+
* Sync select checkboxes with row selections on current page
|
228
|
+
*
|
229
|
+
* @param {DataTable.Api} dt DataTable
|
230
|
+
* @private
|
231
|
+
*/
|
232
|
+
function syncSelectCheckboxes (dt) {
|
233
|
+
var ctx = dt.settings()[0];
|
234
|
+
|
235
|
+
$(ctx._pfSelect.selector, dt.table().container()).prop("checked", false); // Deselect all checkboxes
|
236
|
+
dt.rows({"page": "current", "search": "applied", "selected": true}).every(function (index) {
|
237
|
+
$(ctx._pfSelect.selector, dt.table().row(index).node()).prop("checked", true); // Select checkbox for selected row
|
238
|
+
});
|
239
|
+
syncSelectAllCheckbox(dt);
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* Update selection results text
|
244
|
+
*
|
245
|
+
* @param {DataTable.Api} dt DataTable
|
246
|
+
* @private
|
247
|
+
*/
|
248
|
+
function updateSelectedRowsText (dt) {
|
249
|
+
var ctx = dt.settings()[0];
|
250
|
+
var selectedRows = dt.rows({"selected": true}).flatten().length;
|
251
|
+
var totalRows = dt.rows().flatten().length;
|
252
|
+
if (ctx._pfSelect.results !== undefined && ctx._pfSelect.results.length !== 0) {
|
253
|
+
$(ctx._pfSelect.results).html("<strong>" + selectedRows + "</strong> of <strong>" +
|
254
|
+
totalRows + "</strong> selected");
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
// DataTables API
|
259
|
+
|
260
|
+
/**
|
261
|
+
* Select all rows on current page
|
262
|
+
*
|
263
|
+
* Example: dt.table().pfSelect.selectAllRows(true);
|
264
|
+
*
|
265
|
+
* @param {boolean} select True to select all rows on current page, defaults to false
|
266
|
+
*/
|
267
|
+
DataTable.Api.register("pfSelect.selectAllRows()", function (select) {
|
268
|
+
return this.iterator("table", function (ctx) {
|
269
|
+
selectAllRows(new DataTable.Api(ctx), select);
|
270
|
+
});
|
271
|
+
});
|
272
|
+
|
273
|
+
// DataTables creation
|
274
|
+
$(document).on("preInit.dt.dtSelect", function (e, ctx) {
|
275
|
+
if (e.namespace !== "dt") {
|
276
|
+
return;
|
277
|
+
}
|
278
|
+
DataTable.pfSelect.init(new DataTable.Api(ctx));
|
279
|
+
});
|
280
|
+
return DataTable.pfSelect;
|
281
|
+
}));
|