patternfly-sass 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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(window){"use strict";var patternfly={version:"3.13.0"};patternfly.pfPaletteColors={black:"#030303",black100:"#fafafa",black200:"#ededed",black300:"#d1d1d1",black400:"#bbbbbb",black500:"#8b8d8f",black600:"#72767b",black700:"#4d5258",black800:"#393f44",black900:"#292e34",blue:"#0088ce",blue100:"#bee1f4",blue200:"#7dc3e8",blue300:"#39a5dc",blue400:"#0088ce",blue500:"#00659c",blue600:"#004368",blue700:"#002235",gold:"#f0ab00",gold100:"#fbeabc",gold200:"#f9d67a",gold300:"#f5c12e",gold400:"#f0ab00",gold500:"#b58100",gold600:"#795600",gold700:"#3d2c00",orange:"#ec7a08",orange100:"#fbdebf",orange200:"#f7bd7f",orange300:"#f39d3c",orange400:"#ec7a08",orange500:"#b35c00",orange600:"#773d00",orange700:"#3b1f00",lightBlue:"#00b9e4",lightBlue100:"#beedf9",lightBlue200:"#7cdbf3",lightBlue300:"#35caed",lightBlue400:"#00b9e4",lightBlue500:"#008bad",lightBlue600:"#005c73",lightBlue700:"#002d39",green:"#3f9c35",green100:"#cfe7cd",green200:"#9ecf99",green300:"#6ec664",green400:"#3f9c35",green500:"#2d7623",green600:"#1e4f18",green700:"#0f280d",lightGreen:"#92d400",lightGreen100:"#e4f5bc",lightGreen200:"#c8eb79",lightGreen300:"#ace12e",lightGreen400:"#92d400",lightGreen500:"#6ca100",lightGreen600:"#486b00",lightGreen700:"#253600",cyan:"#007a87",cyan100:"#bedee1",cyan200:"#7dbdc3",cyan300:"#3a9ca6",cyan400:"#007a87",cyan500:"#005c66",cyan600:"#003d44",cyan700:"#001f22",purple:"#703fec",purple100:"#c7bfff",purple200:"#a18fff",purple300:"#8461f7",purple400:"#703fec",purple500:"#582fc0",purple600:"#40199a",purple700:"#1f0066",red:"#cc0000",red100:"#cc0000",red200:"#a30000",red300:"#8b0000",red400:"#470000",red500:"#2c0000"},patternfly.pfSetDonutChartTitle=function(selector,primary,secondary){var donutChartRightTitle=window.d3.select(selector).select("text.c3-chart-arcs-title");donutChartRightTitle.text(""),donutChartRightTitle.insert("tspan").text(primary).classed("donut-title-big-pf",!0).attr("dy",0).attr("x",0),donutChartRightTitle.insert("tspan").text(secondary).classed("donut-title-small-pf",!0).attr("dy",20).attr("x",0)},patternfly.pfDonutTooltipContents=function(d,defaultTitleFormat,defaultValueFormat,color){return'<table class="c3-tooltip"> <tr> <td><span style="background-color:'+color(d[0].id)+'"></span><strong>'+d[0].value+"</strong> "+d[0].name+"</td> <td>"+Math.round(1e3*d[0].ratio)/10+"%</td> </tr></table>"},patternfly.pfGetUtilizationDonutTooltipContentsFn=function(units){return function(d){return'<span class="donut-tooltip-pf" style="white-space: nowrap;">'+Math.round(1e3*d[0].ratio)/10+"% "+units+" "+d[0].name+"</span>"}},patternfly.pfGetBarChartTooltipContentsFn=function(categories){return function(d){var name=categories?categories[d[0].index]:d[0].index;return'<table class="c3-tooltip"> <tr> <td><strong>'+name+":</td> <td>"+d[0].value+"</td> </tr></table>"}},patternfly.pfSingleLineChartTooltipContentsFn=function(categories){return function(d){var name=categories?categories[d[0].index]:d[0].index;return'<table class="c3-tooltip"> <tr> <td><strong>'+name+":</td> <td>"+d[0].value+"</td> </tr></table>"}},patternfly.pfPieTooltipContents=function(d,defaultTitleFormat,defaultValueFormat,color){return patternfly.pfDonutTooltipContents(d,defaultTitleFormat,defaultValueFormat,color)},patternfly.c3ChartDefaults=function(){var getDefaultColors=function(){return{pattern:[patternfly.pfPaletteColors.blue,patternfly.pfPaletteColors.blue300,patternfly.pfPaletteColors.green,patternfly.pfPaletteColors.orange,patternfly.pfPaletteColors.red]}},getDefaultBarGrid=function(){return{y:{show:!0}}},getDefaultBarTooltip=function(categories){return{contents:patternfly.pfGetBarChartTooltipContentsFn(categories)}},getDefaultBarLegend=function(){return{show:!1}},getDefaultBarConfig=function(categories){return{color:this.getDefaultColors(),grid:this.getDefaultBarGrid(),tooltip:this.getDefaultBarTooltip(categories),legend:this.getDefaultBarLegend()}},getDefaultGroupedBarGrid=function(){return{y:{show:!0}}},getDefaultGroupedBarLegend=function(){return{show:!0,position:"bottom"}},getDefaultGroupedBarConfig=function(){return{color:this.getDefaultColors(),grid:this.getDefaultGroupedBarGrid(),legend:this.getDefaultGroupedBarLegend()}},getDefaultDonut=function(title){return{title:title,label:{show:!1},width:11}},getDefaultDonutSize=function(){return{height:171}},getDefaultDonutColors=function(){return{pattern:[patternfly.pfPaletteColors.blue,patternfly.pfPaletteColors.black300]}},getDefaultDonutTooltip=function(){return{show:!1}},getDefaultDonutLegend=function(){return{show:!1}},getDefaultDonutConfig=function(title){return{donut:this.getDefaultDonut(title),size:this.getDefaultDonutSize(),legend:this.getDefaultDonutLegend(),color:this.getDefaultDonutColors(),tooltip:this.getDefaultDonutTooltip()}},getDefaultPie=function(){return{expand:!0,label:{show:!1}}},getDefaultPieSize=function(){return{height:171}},getDefaultPieColors=function(){return{pattern:[patternfly.pfPaletteColors.blue,patternfly.pfPaletteColors.black300]}},getDefaultPieTooltip=function(){return{contents:$().pfPieTooltipContents}},getDefaultPieLegend=function(){return{show:!1}},getDefaultPieConfig=function(){return{pie:this.getDefaultPie(),size:this.getDefaultPieSize(),legend:this.getDefaultPieLegend(),color:this.getDefaultPieColors(),tooltip:this.getDefaultPieTooltip()}},getDefaultSparklineArea=function(){return{zerobased:!0}},getDefaultSparklineSize=function(){return{height:60}},getDefaultSparklineAxis=function(){return{x:{show:!1},y:{show:!1}}},getDefaultSparklineLegend=function(){return{show:!1}},getDefaultSparklinePoint=function(){return{r:1,focus:{expand:{r:4}}}},getDefaultSparklineTooltip=function(){return{contents:function(d){return'<span class="c3-tooltip-sparkline">'+d[0].value+" "+d[0].name+"</span>"}}},getDefaultSparklineConfig=function(){return{area:getDefaultSparklineArea(),size:getDefaultSparklineSize(),axis:getDefaultSparklineAxis(),color:getDefaultColors(),legend:getDefaultSparklineLegend(),point:getDefaultSparklinePoint(),tooltip:getDefaultSparklineTooltip()}},getDefaultLineAxis=function(){return{x:{show:!0},y:{show:!0}}},getDefaultLineGrid=function(){return{x:{show:!1},y:{show:!0}}},getDefaultLineLegend=function(){return{show:!0}},getDefaultLinePoint=function(){return{r:3,focus:{expand:{r:5}}}},getDefaultLineConfig=function(){return{axis:getDefaultLineAxis(),grid:getDefaultLineGrid(),color:getDefaultColors(),legend:getDefaultLineLegend(),point:getDefaultLinePoint()}},getDefaultSingleLineTooltip=function(){return{contents:$().pfGetBarChartTooltipContentsFn()}},getDefaultSingleLineLegend=function(){return{show:!1}},getDefaultSingleLineConfig=function(){return{axis:getDefaultLineAxis(),grid:getDefaultLineGrid(),color:getDefaultColors(),legend:getDefaultSingleLineLegend(),point:getDefaultLinePoint(),tooltip:getDefaultSingleLineTooltip()}},getDefaultAreaAxis=function(){return getDefaultLineAxis()},getDefaultAreaGrid=function(){return getDefaultLineGrid()},getDefaultAreaLegend=function(){return getDefaultLineLegend()},getDefaultAreaPoint=function(){return getDefaultLinePoint()},getDefaultAreaConfig=function(){return{axis:getDefaultAreaAxis(),grid:getDefaultAreaGrid(),color:getDefaultColors(),legend:getDefaultAreaLegend(),point:getDefaultAreaPoint()}},getDefaultSingleAreaTooltip=function(){return{contents:$().pfGetBarChartTooltipContentsFn()}},getDefaultSingleAreaLegend=function(){return getDefaultSingleLineLegend()},getDefaultSingleAreaConfig=function(){return{axis:getDefaultAreaAxis(),grid:getDefaultAreaGrid(),color:getDefaultColors(),legend:getDefaultSingleAreaLegend(),point:getDefaultAreaPoint(),tooltip:getDefaultSingleAreaTooltip()}};return{getDefaultColors:getDefaultColors,getDefaultBarGrid:getDefaultBarGrid,getDefaultBarTooltip:getDefaultBarTooltip,getDefaultBarLegend:getDefaultBarLegend,getDefaultBarConfig:getDefaultBarConfig,getDefaultGroupedBarGrid:getDefaultGroupedBarGrid,getDefaultGroupedBarLegend:getDefaultGroupedBarLegend,getDefaultGroupedBarConfig:getDefaultGroupedBarConfig,getDefaultDonut:getDefaultDonut,getDefaultDonutSize:getDefaultDonutSize,getDefaultDonutColors:getDefaultDonutColors,getDefaultDonutTooltip:getDefaultDonutTooltip,getDefaultDonutLegend:getDefaultDonutLegend,getDefaultDonutConfig:getDefaultDonutConfig,getDefaultPie:getDefaultPie,getDefaultPieSize:getDefaultPieSize,getDefaultPieColors:getDefaultPieColors,getDefaultPieTooltip:getDefaultPieTooltip,getDefaultPieLegend:getDefaultPieLegend,getDefaultPieConfig:getDefaultPieConfig,getDefaultSparklineArea:getDefaultSparklineArea,getDefaultSparklineSize:getDefaultSparklineSize,getDefaultSparklineAxis:getDefaultSparklineAxis,getDefaultSparklineLegend:getDefaultSparklineLegend,getDefaultSparklinePoint:getDefaultSparklinePoint,getDefaultSparklineTooltip:getDefaultSparklineTooltip,getDefaultSparklineConfig:getDefaultSparklineConfig,getDefaultLineAxis:getDefaultLineAxis,getDefaultLineGrid:getDefaultLineGrid,getDefaultLineLegend:getDefaultLineLegend,getDefaultLinePoint:getDefaultLinePoint,getDefaultLineConfig:getDefaultLineConfig,getDefaultSingleLineTooltip:getDefaultSingleLineTooltip,getDefaultSingleLineConfig:getDefaultSingleLineConfig,getDefaultAreaAxis:getDefaultAreaAxis,getDefaultAreaGrid:getDefaultAreaGrid,getDefaultAreaLegend:getDefaultAreaLegend,getDefaultAreaPoint:getDefaultAreaPoint,getDefaultAreaConfig:getDefaultAreaConfig,getDefaultSingleAreaTooltip:getDefaultSingleAreaTooltip,getDefaultSingleAreaConfig:getDefaultSingleAreaConfig}},patternfly.pfBreakpoints={tablet:768,desktop:1200},"function"==typeof define&&define.amd?define("patternfly",function(){return patternfly}):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=patternfly:window.patternfly=patternfly}(window);
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary pfEmpty for DataTables
|
|
3
|
+
* @description A collection of API methods providing functionality to hide and show elements when DataTables is empty.
|
|
4
|
+
* This ensures DataTables meets the Patternfly design pattern with a toolbar and empty state.
|
|
5
|
+
*
|
|
6
|
+
* When DataTable is redrawn and data length is zero, controls under the toolbar-pf-actions and toolbar-pf-results
|
|
7
|
+
* classes are disabled; including the filter drop down, filter input, action buttons, kebab, find, etc. (You may
|
|
8
|
+
* re-enable specific controls via the DataTables "draw.dt" event.) In addition, the DataTables empty table header and
|
|
9
|
+
* row are hidden while the empty state (i.e., blank slate) layout is shown.
|
|
10
|
+
*
|
|
11
|
+
* The toolbar and empty state layouts are expected to contain the classes as shown in the example below.
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
*
|
|
15
|
+
* <!-- NOTE: Some configuration may be omitted for clarity -->
|
|
16
|
+
* <div class="row toolbar-pf table-view-pf-toolbar" id="toolbar1">
|
|
17
|
+
* <div class="col-sm-12">
|
|
18
|
+
* <form class="toolbar-pf-actions">
|
|
19
|
+
* ...
|
|
20
|
+
* </form>
|
|
21
|
+
* <div class="row toolbar-pf-results">
|
|
22
|
+
* ...
|
|
23
|
+
* </div>
|
|
24
|
+
* </div>
|
|
25
|
+
* </div>
|
|
26
|
+
* <table class="table table-striped table-bordered table-hover" id="table1">
|
|
27
|
+
* <thead>
|
|
28
|
+
* <tr>
|
|
29
|
+
* <th><input type="checkbox" name="selectAll"></th>
|
|
30
|
+
* <th>Rendering Engine</th>
|
|
31
|
+
* <th>Browser</th>
|
|
32
|
+
* </tr>
|
|
33
|
+
* </thead>
|
|
34
|
+
* </table>
|
|
35
|
+
* <div class="blank-slate-pf table-view-pf-empty hidden" id="emptyState1">
|
|
36
|
+
* <div class="blank-slate-pf-icon">
|
|
37
|
+
* <span class="pficon pficon pficon-add-circle-o"></span>
|
|
38
|
+
* </div>
|
|
39
|
+
* <h1>Empty State Title</h1>
|
|
40
|
+
* ...
|
|
41
|
+
* </div>
|
|
42
|
+
* <script>
|
|
43
|
+
* // NOTE: Some properties may be omitted for clarity
|
|
44
|
+
* $(document).ready(function() {
|
|
45
|
+
* var dt = $("#table1").DataTable({
|
|
46
|
+
* columns: [
|
|
47
|
+
* { data: null, ... },
|
|
48
|
+
* { data: "engine" },
|
|
49
|
+
* { data: "browser" }
|
|
50
|
+
* ],
|
|
51
|
+
* data: null,
|
|
52
|
+
* dom: "t",
|
|
53
|
+
* pfConfig: {
|
|
54
|
+
* emptyStateSelector: "#{{include.emptyStateId}}",
|
|
55
|
+
* ...
|
|
56
|
+
* toolbarSelector: "#{{include.toolbarId}}"
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
* dt.table().pfEmpty.updateState(); // Optional API to force update
|
|
60
|
+
* });
|
|
61
|
+
* </script>
|
|
62
|
+
*
|
|
63
|
+
* Note: This functionality requires the following Javascript library files to be loaded:
|
|
64
|
+
*
|
|
65
|
+
* https://cdn.datatables.net/select/1.2.0/js/dataTables.select.min.js
|
|
66
|
+
*/
|
|
67
|
+
(function (factory) {
|
|
68
|
+
"use strict";
|
|
69
|
+
if (typeof define === "function" && define.amd ) {
|
|
70
|
+
// AMD
|
|
71
|
+
define (["jquery", "datatables.net"], function ($) {
|
|
72
|
+
return factory ($, window, document);
|
|
73
|
+
});
|
|
74
|
+
} else if (typeof exports === "object") {
|
|
75
|
+
// CommonJS
|
|
76
|
+
module.exports = function (root, $) {
|
|
77
|
+
if (!root) {
|
|
78
|
+
root = window;
|
|
79
|
+
}
|
|
80
|
+
if (!$ || !$.fn.dataTable) {
|
|
81
|
+
$ = require("datatables.net")(root, $).$;
|
|
82
|
+
}
|
|
83
|
+
return factory($, root, root.document);
|
|
84
|
+
};
|
|
85
|
+
} else {
|
|
86
|
+
// Browser
|
|
87
|
+
factory(jQuery, window, document);
|
|
88
|
+
}
|
|
89
|
+
}(function ($, window, document, undefined) {
|
|
90
|
+
"use strict";
|
|
91
|
+
var DataTable = $.fn.dataTable;
|
|
92
|
+
var ACTIONS_SELECTOR = ".toolbar-pf-actions"; // Toolbar actions
|
|
93
|
+
var RESULTS_SELECTOR = ".toolbar-pf-results"; // Toolbar results row
|
|
94
|
+
|
|
95
|
+
DataTable.pfEmpty = {};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Initialize
|
|
99
|
+
*
|
|
100
|
+
* @param {DataTable.Api} dt DataTable
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
DataTable.pfEmpty.init = function (dt) {
|
|
104
|
+
var ctx = dt.settings()[0];
|
|
105
|
+
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
|
|
106
|
+
|
|
107
|
+
ctx._pfEmpty = {};
|
|
108
|
+
ctx._pfEmpty.emptyState = $(opts.emptyStateSelector); // Empty state (Blank slate)
|
|
109
|
+
ctx._pfEmpty.isEmptyState = false; // Flag indicating DatTable entered an empty state
|
|
110
|
+
ctx._pfEmpty.tbody = $("tbody", dt.table().container()); // Table body
|
|
111
|
+
ctx._pfEmpty.thead = $("thead", dt.table().container()); // Table head
|
|
112
|
+
ctx._pfEmpty.toolbarActions = $(ACTIONS_SELECTOR, opts.toolbarSelector); // Toolbar actions
|
|
113
|
+
ctx._pfEmpty.toolbarResults = $(RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar results row
|
|
114
|
+
|
|
115
|
+
// Update table on DataTables draw event
|
|
116
|
+
dt.on("draw.dt", function () {
|
|
117
|
+
updateState(dt);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Initialize
|
|
121
|
+
updateState(dt);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Local functions
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Disable and hide elements when DataTables has no data
|
|
128
|
+
*
|
|
129
|
+
* @param {DataTable.Api} dt DataTable
|
|
130
|
+
* @private
|
|
131
|
+
*/
|
|
132
|
+
function updateEmptyState (dt) {
|
|
133
|
+
var ctx = dt.settings()[0];
|
|
134
|
+
|
|
135
|
+
// Show blank slate
|
|
136
|
+
if (ctx._pfEmpty.emptyState !== undefined && ctx._pfEmpty.emptyState.length !== 0) {
|
|
137
|
+
ctx._pfEmpty.emptyState.removeClass("hidden");
|
|
138
|
+
}
|
|
139
|
+
// Hide zero records message
|
|
140
|
+
if (ctx._pfEmpty.tbody !== undefined && ctx._pfEmpty.tbody.length !== 0) {
|
|
141
|
+
ctx._pfEmpty.tbody.addClass("hidden");
|
|
142
|
+
}
|
|
143
|
+
// Hide column headers
|
|
144
|
+
if (ctx._pfEmpty.thead !== undefined && ctx._pfEmpty.thead.length !== 0) {
|
|
145
|
+
ctx._pfEmpty.thead.addClass("hidden");
|
|
146
|
+
}
|
|
147
|
+
// Disable all buttons
|
|
148
|
+
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
|
|
149
|
+
$("button", ctx._pfEmpty.toolbarActions).prop("disabled", true);
|
|
150
|
+
}
|
|
151
|
+
// Disable all inputs
|
|
152
|
+
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
|
|
153
|
+
$("input", ctx._pfEmpty.toolbarActions).prop("disabled", true);
|
|
154
|
+
}
|
|
155
|
+
// Hide results container
|
|
156
|
+
if (ctx._pfEmpty.toolbarResults !== undefined && ctx._pfEmpty.toolbarResults.length !== 0) {
|
|
157
|
+
ctx._pfEmpty.toolbarResults.children().addClass("hidden");
|
|
158
|
+
}
|
|
159
|
+
// Enable on empty
|
|
160
|
+
if (ctx._pfEmpty.enableOnEmpty !== undefined) {
|
|
161
|
+
$(ctx._pfEmpty.enableOnEmpty).prop("disabled", false);
|
|
162
|
+
}
|
|
163
|
+
// Enable on empty
|
|
164
|
+
if (ctx._pfEmpty.enableOnEmpty !== undefined) {
|
|
165
|
+
$(ctx._pfEmpty.enableOnEmpty).prop("disabled", false);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Enable and show elements when DataTables has data
|
|
171
|
+
*
|
|
172
|
+
* @param {DataTable.Api} dt DataTable
|
|
173
|
+
* @private
|
|
174
|
+
*/
|
|
175
|
+
function updateNonEmptyState (dt) {
|
|
176
|
+
var ctx = dt.settings()[0];
|
|
177
|
+
|
|
178
|
+
// Hide blank slate
|
|
179
|
+
if (ctx._pfEmpty.emptyState !== undefined && ctx._pfEmpty.emptyState.length !== 0) {
|
|
180
|
+
ctx._pfEmpty.emptyState.addClass("hidden");
|
|
181
|
+
}
|
|
182
|
+
// Show table body
|
|
183
|
+
if (ctx._pfEmpty.tbody !== undefined && ctx._pfEmpty.tbody.length !== 0) {
|
|
184
|
+
ctx._pfEmpty.tbody.removeClass("hidden");
|
|
185
|
+
}
|
|
186
|
+
// Show column headers
|
|
187
|
+
if (ctx._pfEmpty.thead !== undefined && ctx._pfEmpty.thead.length !== 0) {
|
|
188
|
+
ctx._pfEmpty.thead.removeClass("hidden");
|
|
189
|
+
}
|
|
190
|
+
// Enable all buttons
|
|
191
|
+
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
|
|
192
|
+
$("button", ctx._pfEmpty.toolbarActions).prop("disabled", false);
|
|
193
|
+
}
|
|
194
|
+
// Enable all inputs
|
|
195
|
+
if (ctx._pfEmpty.toolbarActions !== undefined && ctx._pfEmpty.toolbarActions.length !== 0) {
|
|
196
|
+
$("input", ctx._pfEmpty.toolbarActions).prop("disabled", false);
|
|
197
|
+
}
|
|
198
|
+
// Show results container
|
|
199
|
+
if (ctx._pfEmpty.toolbarResults !== undefined && ctx._pfEmpty.toolbarResults.length !== 0) {
|
|
200
|
+
ctx._pfEmpty.toolbarResults.children().removeClass("hidden");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Update elements upon empty DataTable state
|
|
206
|
+
*
|
|
207
|
+
* @param {DataTable.Api} dt DataTable
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
function updateState (dt) {
|
|
211
|
+
var ctx = dt.settings()[0];
|
|
212
|
+
|
|
213
|
+
// Don't enable or show elements unless DataTable was empty
|
|
214
|
+
if (dt.data().length === 0) {
|
|
215
|
+
ctx._pfEmpty.isEmptyState = true;
|
|
216
|
+
updateEmptyState(dt);
|
|
217
|
+
} else if (ctx._pfEmpty.isEmptyState === true) {
|
|
218
|
+
ctx._pfEmpty.isEmptyState = false;
|
|
219
|
+
updateNonEmptyState(dt);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// DataTables API
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Update state upon empty or non-empty DataTable
|
|
227
|
+
*
|
|
228
|
+
* Example: dt.table().pfEmpty.updateState();
|
|
229
|
+
*/
|
|
230
|
+
DataTable.Api.register("pfEmpty.updateState()", function () {
|
|
231
|
+
return this.iterator("table", function (ctx) {
|
|
232
|
+
update(new DataTable.Api(ctx));
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// DataTables creation
|
|
237
|
+
$(document).on("init.dt", function (e, ctx, json) {
|
|
238
|
+
if (e.namespace !== "dt") {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
DataTable.pfEmpty.init(new DataTable.Api(ctx));
|
|
242
|
+
});
|
|
243
|
+
return DataTable.pfEmpty;
|
|
244
|
+
}));
|
|
@@ -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 updateEmptyState(dt){var ctx=dt.settings()[0];ctx._pfEmpty.emptyState!==undefined&&0!==ctx._pfEmpty.emptyState.length&&ctx._pfEmpty.emptyState.removeClass("hidden"),ctx._pfEmpty.tbody!==undefined&&0!==ctx._pfEmpty.tbody.length&&ctx._pfEmpty.tbody.addClass("hidden"),ctx._pfEmpty.thead!==undefined&&0!==ctx._pfEmpty.thead.length&&ctx._pfEmpty.thead.addClass("hidden"),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("button",ctx._pfEmpty.toolbarActions).prop("disabled",!0),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("input",ctx._pfEmpty.toolbarActions).prop("disabled",!0),ctx._pfEmpty.toolbarResults!==undefined&&0!==ctx._pfEmpty.toolbarResults.length&&ctx._pfEmpty.toolbarResults.children().addClass("hidden"),ctx._pfEmpty.enableOnEmpty!==undefined&&$(ctx._pfEmpty.enableOnEmpty).prop("disabled",!1),ctx._pfEmpty.enableOnEmpty!==undefined&&$(ctx._pfEmpty.enableOnEmpty).prop("disabled",!1)}function updateNonEmptyState(dt){var ctx=dt.settings()[0];ctx._pfEmpty.emptyState!==undefined&&0!==ctx._pfEmpty.emptyState.length&&ctx._pfEmpty.emptyState.addClass("hidden"),ctx._pfEmpty.tbody!==undefined&&0!==ctx._pfEmpty.tbody.length&&ctx._pfEmpty.tbody.removeClass("hidden"),ctx._pfEmpty.thead!==undefined&&0!==ctx._pfEmpty.thead.length&&ctx._pfEmpty.thead.removeClass("hidden"),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("button",ctx._pfEmpty.toolbarActions).prop("disabled",!1),ctx._pfEmpty.toolbarActions!==undefined&&0!==ctx._pfEmpty.toolbarActions.length&&$("input",ctx._pfEmpty.toolbarActions).prop("disabled",!1),ctx._pfEmpty.toolbarResults!==undefined&&0!==ctx._pfEmpty.toolbarResults.length&&ctx._pfEmpty.toolbarResults.children().removeClass("hidden")}function updateState(dt){var ctx=dt.settings()[0];0===dt.data().length?(ctx._pfEmpty.isEmptyState=!0,updateEmptyState(dt)):ctx._pfEmpty.isEmptyState===!0&&(ctx._pfEmpty.isEmptyState=!1,updateNonEmptyState(dt))}var DataTable=$.fn.dataTable,ACTIONS_SELECTOR=".toolbar-pf-actions",RESULTS_SELECTOR=".toolbar-pf-results";return DataTable.pfEmpty={},DataTable.pfEmpty.init=function(dt){var ctx=dt.settings()[0],opts=ctx.oInit.pfConfig?ctx.oInit.pfConfig:{};ctx._pfEmpty={},ctx._pfEmpty.emptyState=$(opts.emptyStateSelector),ctx._pfEmpty.isEmptyState=!1,ctx._pfEmpty.tbody=$("tbody",dt.table().container()),ctx._pfEmpty.thead=$("thead",dt.table().container()),ctx._pfEmpty.toolbarActions=$(ACTIONS_SELECTOR,opts.toolbarSelector),ctx._pfEmpty.toolbarResults=$(RESULTS_SELECTOR,opts.toolbarSelector),dt.on("draw.dt",function(){updateState(dt)}),updateState(dt)},DataTable.Api.register("pfEmpty.updateState()",function(){return this.iterator("table",function(ctx){update(new DataTable.Api(ctx))})}),$(document).on("init.dt",function(e,ctx,json){"dt"===e.namespace&&DataTable.pfEmpty.init(new DataTable.Api(ctx))}),DataTable.pfEmpty});
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary pfFilter for DataTables
|
|
3
|
+
* @description A collection of API methods providing simple filter functionality for DataTables. This ensures
|
|
4
|
+
* DataTables meets the Patternfly design pattern with a toolbar.
|
|
5
|
+
*
|
|
6
|
+
* To apply a filter, the user must press enter in the given filter input. The user may apply a filter to a different
|
|
7
|
+
* column via the given filter drop down. After a filter has been applied, the filter results text, active filter
|
|
8
|
+
* controls, and a clear all control are shown.
|
|
9
|
+
*
|
|
10
|
+
* The toolbar and empty state layouts are expected to contain the classes as shown in the example below.
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
*
|
|
14
|
+
* <!-- NOTE: Some configuration may be omitted for clarity -->
|
|
15
|
+
* <div class="row toolbar-pf table-view-pf-toolbar" id="toolbar1">
|
|
16
|
+
* <div class="col-sm-12">
|
|
17
|
+
* <form class="toolbar-pf-actions">
|
|
18
|
+
* <div class="form-group toolbar-pf-filter">
|
|
19
|
+
* <label class="sr-only" for="filter">Rendering Engine</label>
|
|
20
|
+
* <div class="input-group">
|
|
21
|
+
* <div class="input-group-btn">
|
|
22
|
+
* <button type="button" class="btn btn-default dropdown-toggle" id="filter" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Rendering Engine <span class="caret"></span></button>
|
|
23
|
+
* <ul class="dropdown-menu">
|
|
24
|
+
* <li><a href="#" id="filter1">Rendering Engine</a></li>
|
|
25
|
+
* <li><a href="#" id="filter2">Browser</a></li>
|
|
26
|
+
* </ul>
|
|
27
|
+
* </div>
|
|
28
|
+
* <input type="text" class="form-control" placeholder="Filter By Rendering Engine..." autocomplete="off" id="filterInput">
|
|
29
|
+
* </div>
|
|
30
|
+
* </div>
|
|
31
|
+
* ...
|
|
32
|
+
* </form>
|
|
33
|
+
* <div class="row toolbar-pf-results">
|
|
34
|
+
* <div class="col-sm-9">
|
|
35
|
+
* <div class="hidden">
|
|
36
|
+
* <h5>0 Results</h5>
|
|
37
|
+
* <p>Active filters:</p>
|
|
38
|
+
* <ul class="list-inline"></ul>
|
|
39
|
+
* <p><a href="#">Clear All Filters</a></p>
|
|
40
|
+
* </div>
|
|
41
|
+
* </div>
|
|
42
|
+
* <div class="col-sm-3 table-view-pf-select-results">
|
|
43
|
+
* <strong>0</strong> of <strong>0</strong> selected
|
|
44
|
+
* </div>
|
|
45
|
+
* </div>
|
|
46
|
+
* </div>
|
|
47
|
+
* </div>
|
|
48
|
+
* <table class="table table-striped table-bordered table-hover" id="table1">
|
|
49
|
+
* <thead>
|
|
50
|
+
* <tr>
|
|
51
|
+
* <th><input type="checkbox" name="selectAll"></th>
|
|
52
|
+
* <th>Rendering Engine</th>
|
|
53
|
+
* <th>Browser</th>
|
|
54
|
+
* </tr>
|
|
55
|
+
* </thead>
|
|
56
|
+
* </table>
|
|
57
|
+
* ...
|
|
58
|
+
* <script>
|
|
59
|
+
* // NOTE: Some properties may be omitted for clarity
|
|
60
|
+
* $(document).ready(function() {
|
|
61
|
+
* var dt = $("#table1").DataTable({
|
|
62
|
+
* columns: [
|
|
63
|
+
* { data: null, ... },
|
|
64
|
+
* { data: "engine" },
|
|
65
|
+
* { data: "browser" }
|
|
66
|
+
* ],
|
|
67
|
+
* data: [
|
|
68
|
+
* { engine: "Gecko", browser: "Firefox" }
|
|
69
|
+
* { engine: "Trident", browser: "Mozilla" }
|
|
70
|
+
* ],
|
|
71
|
+
* dom: "t",
|
|
72
|
+
* pfConfig: {
|
|
73
|
+
* ...
|
|
74
|
+
* filterCols: [
|
|
75
|
+
* null,
|
|
76
|
+
* {
|
|
77
|
+
* default: true,
|
|
78
|
+
* optionSelector: "#{{include.filterId1}}",
|
|
79
|
+
* placeholder: "Filter By Rendering Engine..."
|
|
80
|
+
* }, {
|
|
81
|
+
* optionSelector: "#{{include.filterId2}}",
|
|
82
|
+
* placeholder: "Filter By Browser..."
|
|
83
|
+
* }
|
|
84
|
+
* ],
|
|
85
|
+
* toolbarSelector: "#{{include.toolbarId}}"
|
|
86
|
+
* }
|
|
87
|
+
* });
|
|
88
|
+
* // Optional API to clear filters
|
|
89
|
+
* dt.table().pfFilter.clearFilters();
|
|
90
|
+
*
|
|
91
|
+
* // Optional API to add filter
|
|
92
|
+
* dt.table().pfFilter.addFilter({
|
|
93
|
+
* column: 2,
|
|
94
|
+
* name: "Browser",
|
|
95
|
+
* value: "Firefox"
|
|
96
|
+
* });
|
|
97
|
+
* });
|
|
98
|
+
* </script>
|
|
99
|
+
*
|
|
100
|
+
* Note: This functionality requires the following Javascript library files to be loaded:
|
|
101
|
+
*
|
|
102
|
+
* https://cdn.datatables.net/select/1.2.0/js/dataTables.select.min.js
|
|
103
|
+
*/
|
|
104
|
+
(function (factory) {
|
|
105
|
+
"use strict";
|
|
106
|
+
if (typeof define === "function" && define.amd ) {
|
|
107
|
+
// AMD
|
|
108
|
+
define (["jquery", "datatables.net"], function ($) {
|
|
109
|
+
return factory ($, window, document);
|
|
110
|
+
});
|
|
111
|
+
} else if (typeof exports === "object") {
|
|
112
|
+
// CommonJS
|
|
113
|
+
module.exports = function (root, $) {
|
|
114
|
+
if (!root) {
|
|
115
|
+
root = window;
|
|
116
|
+
}
|
|
117
|
+
if (!$ || !$.fn.dataTable) {
|
|
118
|
+
$ = require("datatables.net")(root, $).$;
|
|
119
|
+
}
|
|
120
|
+
return factory($, root, root.document);
|
|
121
|
+
};
|
|
122
|
+
} else {
|
|
123
|
+
// Browser
|
|
124
|
+
factory(jQuery, window, document);
|
|
125
|
+
}
|
|
126
|
+
}(function ($, window, document, undefined) {
|
|
127
|
+
"use strict";
|
|
128
|
+
var DataTable = $.fn.dataTable;
|
|
129
|
+
var ACTIVE_FILTER_CONTROLS_SELECTOR = ".list-inline"; // Active filter controls
|
|
130
|
+
var CLEAR_FILTERS_SELECTOR = ".toolbar-pf-results a"; // Clear filters control
|
|
131
|
+
var FILTER_SELECTOR = ".toolbar-pf-filter"; // Filter input
|
|
132
|
+
var FILTER_BUTTON_SELECTOR = FILTER_SELECTOR + " button"; // Filter button
|
|
133
|
+
var FILTER_INPUT_SELECTOR = FILTER_SELECTOR + " input"; // Filter input
|
|
134
|
+
var FILTER_LABEL_SELECTOR = FILTER_SELECTOR + " label"; // Filter label
|
|
135
|
+
var RESULTS_SELECTOR = ".toolbar-pf-results"; // Toolbar results row
|
|
136
|
+
var FILTER_RESULTS_SELECTOR = RESULTS_SELECTOR + " h5"; // Toolbar filter results
|
|
137
|
+
|
|
138
|
+
DataTable.pfFilter = {};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Initialize
|
|
142
|
+
*
|
|
143
|
+
* @param {DataTable.Api} dt DataTable
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
DataTable.pfFilter.init = function (dt) {
|
|
147
|
+
var i;
|
|
148
|
+
var ctx = dt.settings()[0];
|
|
149
|
+
var opts = (ctx.oInit.pfConfig) ? ctx.oInit.pfConfig : {};
|
|
150
|
+
|
|
151
|
+
ctx._pfFilter = {};
|
|
152
|
+
ctx._pfFilter.filterButton = $(FILTER_BUTTON_SELECTOR, opts.toolbarSelector); // Filter button
|
|
153
|
+
ctx._pfFilter.filterCols = opts.filterCols; // Filter colums config
|
|
154
|
+
ctx._pfFilter.filterLabel = $(FILTER_LABEL_SELECTOR, opts.toolbarSelector); // Filter label
|
|
155
|
+
ctx._pfFilter.filterInput = $(FILTER_INPUT_SELECTOR, opts.toolbarSelector); // Filter input
|
|
156
|
+
ctx._pfFilter.filters = []; // Applied filters array
|
|
157
|
+
ctx._pfFilter.activeFilterControls = $(ACTIVE_FILTER_CONTROLS_SELECTOR, opts.toolbarSelector); // Active filter controls
|
|
158
|
+
ctx._pfFilter.activeFilters = ctx._pfFilter.activeFilterControls.closest("div"); // Active filters container
|
|
159
|
+
ctx._pfFilter.clearFilters = $(CLEAR_FILTERS_SELECTOR, opts.toolbarSelector); // Clear filters control
|
|
160
|
+
ctx._pfFilter.results = $(RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar results row
|
|
161
|
+
ctx._pfFilter.filterResults = $(FILTER_RESULTS_SELECTOR, opts.toolbarSelector); // Toolbar filter results
|
|
162
|
+
|
|
163
|
+
if (ctx._pfFilter.filterCols === undefined) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Set default filter properties
|
|
168
|
+
for (i = 0; i < ctx._pfFilter.filterCols.length; i++) {
|
|
169
|
+
if (ctx._pfFilter.filterCols[i] === null) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
ctx._pfFilter.filterColumn = i; // Current filter column
|
|
173
|
+
ctx._pfFilter.filterName = $(ctx._pfFilter.filterCols[i].optionSelector).text(); // Name of current filter
|
|
174
|
+
if (ctx._pfFilter.filterCols[i].default === true) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Handle click on filter menu to set current filter column and name
|
|
180
|
+
for (i = 0; i < ctx._pfFilter.filterCols.length; i++) {
|
|
181
|
+
handleFilterOption(dt, i); // Need to pass value of i as a function
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Handle actions when enter is pressed within filter input
|
|
185
|
+
handleFilterInput(dt);
|
|
186
|
+
|
|
187
|
+
// Handle actions when clear filters control is selected
|
|
188
|
+
handleClearFilters(dt);
|
|
189
|
+
|
|
190
|
+
// Simple filter
|
|
191
|
+
$.fn.dataTable.ext.search.push(function (ctx, data, dataIndex) {
|
|
192
|
+
var showThisRow = true;
|
|
193
|
+
// Must match all filters
|
|
194
|
+
if (ctx._pfFilter) {
|
|
195
|
+
$.each(ctx._pfFilter.filters, function (index, filter) {
|
|
196
|
+
if (data[filter.column].indexOf(filter.value) === -1) {
|
|
197
|
+
showThisRow = false;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return showThisRow;
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Local functions
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Add active filter control
|
|
209
|
+
*
|
|
210
|
+
* @param {DataTable.Api} dt DataTable
|
|
211
|
+
* @param {object} filter Properties associated with a new filter
|
|
212
|
+
* @param {string} filter.column - Column associated with DataTable
|
|
213
|
+
* @param {string} filter.name - Name of the filter
|
|
214
|
+
* @param {string} filter.value - Value of the filter
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
function addActiveFilterControl (dt, filter) {
|
|
218
|
+
var ctx = dt.settings()[0];
|
|
219
|
+
var i;
|
|
220
|
+
|
|
221
|
+
// Append active filter control
|
|
222
|
+
ctx._pfFilter.activeFilterControls.append('<li><span class="label label-info">' + filter.name + ': ' +
|
|
223
|
+
filter.value + '<a href="#"><span class="pficon pficon-close"/></a></span></li>');
|
|
224
|
+
|
|
225
|
+
// Handle click to clear active filter
|
|
226
|
+
$("a", ctx._pfFilter.activeFilterControls).last().on("click", function (e) {
|
|
227
|
+
// Find existing filter and remove
|
|
228
|
+
for (i = 0; i < ctx._pfFilter.filters.length; i++) {
|
|
229
|
+
if (ctx._pfFilter.filters[i].column === filter.column && ctx._pfFilter.filters[i].value === filter.value) {
|
|
230
|
+
ctx._pfFilter.filters.splice(i, 1);
|
|
231
|
+
$(this).parents("li").remove();
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (ctx._pfFilter.filters.length === 0) {
|
|
236
|
+
ctx._pfFilter.activeFilters.addClass("hidden"); // Hide
|
|
237
|
+
}
|
|
238
|
+
dt.draw();
|
|
239
|
+
updateFilterResults(dt);
|
|
240
|
+
});
|
|
241
|
+
// Show active filters
|
|
242
|
+
ctx._pfFilter.activeFilters.removeClass("hidden");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Add filter
|
|
247
|
+
*
|
|
248
|
+
* @param {DataTable.Api} dt DataTable
|
|
249
|
+
* @param {object} filter Properties associated with a new filter
|
|
250
|
+
* @param {string} filter.column - Column associated with DataTable
|
|
251
|
+
* @param {string} filter.name - Name of the filter
|
|
252
|
+
* @param {string} filter.value - Value of the filter
|
|
253
|
+
* @private
|
|
254
|
+
*/
|
|
255
|
+
function addFilter (dt, filter) {
|
|
256
|
+
var ctx = dt.settings()[0];
|
|
257
|
+
var found = false;
|
|
258
|
+
|
|
259
|
+
// Find existing entry
|
|
260
|
+
$.grep(ctx._pfFilter.filters, function (f) {
|
|
261
|
+
if (f.column === filter.column && f.value === filter.value) {
|
|
262
|
+
found = true;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Add new filter
|
|
267
|
+
if (!found) {
|
|
268
|
+
ctx._pfFilter.filters.push(filter);
|
|
269
|
+
dt.draw();
|
|
270
|
+
addActiveFilterControl(dt, filter);
|
|
271
|
+
updateFilterResults(dt);
|
|
272
|
+
}
|
|
273
|
+
ctx._pfFilter.filterInput.val(""); // Clear input
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Clear filters
|
|
278
|
+
*
|
|
279
|
+
* @param {DataTable.Api} dt DataTable
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
function clearFilters (dt) {
|
|
283
|
+
var ctx = dt.settings()[0];
|
|
284
|
+
ctx._pfFilter.filters.length = 0; // Reset filters
|
|
285
|
+
ctx._pfFilter.activeFilterControls.html(""); // Remove active filter controls
|
|
286
|
+
ctx._pfFilter.activeFilters.addClass("hidden"); // Hide active filters area
|
|
287
|
+
dt.draw();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Handle actions when clear filters control is selected
|
|
292
|
+
*
|
|
293
|
+
* @param {DataTable.Api} dt DataTable
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
function handleClearFilters (dt) {
|
|
297
|
+
var ctx = dt.settings()[0];
|
|
298
|
+
if (ctx._pfFilter.clearFilters === undefined || ctx._pfFilter.clearFilters.length === 0) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
ctx._pfFilter.clearFilters.on("click", function (e) {
|
|
302
|
+
clearFilters(dt);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Handle actions when enter is pressed within filter input
|
|
308
|
+
*
|
|
309
|
+
* @param {DataTable.Api} dt DataTable
|
|
310
|
+
* @private
|
|
311
|
+
*/
|
|
312
|
+
function handleFilterInput (dt) {
|
|
313
|
+
var ctx = dt.settings()[0];
|
|
314
|
+
if (ctx._pfFilter.filterInput === undefined || ctx._pfFilter.filterInput.length === 0) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
ctx._pfFilter.filterInput.on("keypress", function (e) {
|
|
318
|
+
var keycode = (e.keyCode ? e.keyCode : e.which);
|
|
319
|
+
if (keycode === 13) {
|
|
320
|
+
e.preventDefault();
|
|
321
|
+
if (this.value.trim().length > 0) {
|
|
322
|
+
addFilter(dt, {
|
|
323
|
+
column: ctx._pfFilter.filterColumn,
|
|
324
|
+
name: ctx._pfFilter.filterName,
|
|
325
|
+
value: this.value
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Handle actions when filter options are selected
|
|
336
|
+
*
|
|
337
|
+
* @param {DataTable.Api} dt DataTable
|
|
338
|
+
* @param {number} i The column associated with this handler
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
function handleFilterOption (dt, i) {
|
|
342
|
+
var ctx = dt.settings()[0];
|
|
343
|
+
if (ctx._pfFilter.filterCols[i] === null || ctx._pfFilter.filterCols[i].optionSelector === undefined) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
$(ctx._pfFilter.filterCols[i].optionSelector).on("click", function (e) {
|
|
347
|
+
// Set input placeholder
|
|
348
|
+
if (ctx._pfFilter.filterInput !== undefined && ctx._pfFilter.filterInput.length !== 0) {
|
|
349
|
+
ctx._pfFilter.filterInput.get(0).placeholder = ctx._pfFilter.filterCols[i].placeholder;
|
|
350
|
+
}
|
|
351
|
+
// Set filter label
|
|
352
|
+
if (ctx._pfFilter.filterLabel !== undefined && ctx._pfFilter.filterLabel.length !== 0) {
|
|
353
|
+
ctx._pfFilter.filterLabel.html($(this).text());
|
|
354
|
+
}
|
|
355
|
+
// Set filter button
|
|
356
|
+
if (ctx._pfFilter.filterButton !== undefined && ctx._pfFilter.filterButton.length !== 0) {
|
|
357
|
+
ctx._pfFilter.filterButton.html($(this).text() + ' <span class="caret"></span>');
|
|
358
|
+
}
|
|
359
|
+
ctx._pfFilter.filterColumn = i; // Save filter column when applying filter
|
|
360
|
+
ctx._pfFilter.filterName = $(this).text(); // Save filter name for active filter control
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Update active filter results
|
|
366
|
+
*
|
|
367
|
+
* @param {DataTable.Api} dt DataTable
|
|
368
|
+
* @private
|
|
369
|
+
*/
|
|
370
|
+
function updateFilterResults (dt) {
|
|
371
|
+
var ctx = dt.settings()[0];
|
|
372
|
+
var filteredRows = dt.rows({"page": "current", "search": "applied"}).flatten().length;
|
|
373
|
+
if (ctx._pfFilter.filterResults === undefined || ctx._pfFilter.filterResults.length === 0) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
ctx._pfFilter.filterResults.html(filteredRows + " Results");
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// DataTables API
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Add filter
|
|
383
|
+
*
|
|
384
|
+
* Example: dt.table().pfFilter.addFilter({
|
|
385
|
+
* column: 2,
|
|
386
|
+
* name: "Browser",
|
|
387
|
+
* value: "Firefox"
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* @param {object} filter Properties associated with a new filter
|
|
391
|
+
* @param {string} filter.column - Column associated with DataTable
|
|
392
|
+
* @param {string} filter.name - Name of the filter
|
|
393
|
+
* @param {string} filter.value - Value of the filter
|
|
394
|
+
*/
|
|
395
|
+
DataTable.Api.register("pfFilter.addFilter()", function (filter) {
|
|
396
|
+
return this.iterator("table", function (ctx) {
|
|
397
|
+
addFilter(new DataTable.Api(ctx), filter);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Clear filters
|
|
403
|
+
*
|
|
404
|
+
* Example: dt.table().pfFilter.clearFilters();
|
|
405
|
+
*
|
|
406
|
+
*/
|
|
407
|
+
DataTable.Api.register("pfFilter.clearFilters()", function () {
|
|
408
|
+
return this.iterator("table", function (ctx) {
|
|
409
|
+
clearFilters(new DataTable.Api(ctx));
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// DataTables creation
|
|
414
|
+
$(document).on("init.dt", function (e, ctx, json) {
|
|
415
|
+
if (e.namespace !== "dt") {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
DataTable.pfFilter.init(new DataTable.Api(ctx));
|
|
419
|
+
});
|
|
420
|
+
return DataTable.pfFilter;
|
|
421
|
+
}));
|