Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

fix(pfFilter): fix plugin filters do not work if tables are set up serverSide #1095

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"bootstrap-touchspin": "~3.1.1",
"c3": "~0.4.11",
"d3": "~3.5.17",
"datatables": "^1.10.18",
"datatables.net": "^1.10.15",
"datatables.net-colreorder": "^1.4.1",
"datatables.net-colreorder-bs": "~1.3.2",
Expand Down
64 changes: 59 additions & 5 deletions src/js/patternfly.dataTables.pfFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
*/
(function (factory) {
"use strict";
if (typeof define === "function" && define.amd ) {
if (typeof define === "function" && define.amd) {
// AMD
define (["jquery", "datatables.net"], function ($) {
return factory ($, window, document);
define(["jquery", "datatables.net"], function ($) {
return factory($, window, document);
});
} else if (typeof exports === "object") {
// CommonJS
Expand Down Expand Up @@ -208,10 +208,46 @@
}
return showThisRow;
});

$.event.trigger({
type: "init.pf",
message: "pfFilter has been initialized",
time: new Date()
});
};

// Local functions

/**
* update filters if server-side processing is enabled
* see more https://www.datatables.net/release-datatables/examples/data_sources/server_side.html
*
* @param {DataTable.Api} dt DataTable
* @private
*/
function updateRemoteFilters (dt) {
var ctx = dt.settings()[0];
var filters = [];

$.each(ctx._pfFilter.filters, function (index, filter) {
if (filters[filter.column] === undefined) {
filters[filter.column] = [];
}

filters[filter.column].push(filter.value);
});

dt.search('').columns().search(''); // clear before update

$.each(filters, function (column, values) {
if (values === undefined) {
return;
}

dt.column(column).search(values.join('|'), true, false, ctx._pfFilter.filterCaseInsensitive);
});
}

/**
* Add active filter control
*
Expand All @@ -227,7 +263,7 @@
var i;

// Append active filter control
ctx._pfFilter.activeFilterControls.append('<li><span class="label label-info">' + filter.name + ': ' +
ctx._pfFilter.activeFilterControls.append('<li><span class="label label-primary">' + filter.name + ': ' +
filter.value + '<a href="#"><span class="pficon pficon-close"/></a></span></li>');

// Handle click to clear active filter
Expand All @@ -243,6 +279,9 @@
if (ctx._pfFilter.filters.length === 0) {
ctx._pfFilter.activeFilters.addClass("hidden"); // Hide
}
if (ctx.oInit.serverSide) {
updateRemoteFilters(dt);
}
dt.draw();
updateFilterResults(dt);
});
Expand Down Expand Up @@ -274,6 +313,9 @@
// Add new filter
if (!found) {
ctx._pfFilter.filters.push(filter);
if (ctx.oInit.serverSide) {
updateRemoteFilters(dt);
}
dt.draw();
addActiveFilterControl(dt, filter);
updateFilterResults(dt);
Expand All @@ -292,6 +334,9 @@
ctx._pfFilter.filters.length = 0; // Reset filters
ctx._pfFilter.activeFilterControls.html(""); // Remove active filter controls
ctx._pfFilter.activeFilters.addClass("hidden"); // Hide active filters area
if (ctx.oInit.serverSide) {
updateRemoteFilters(dt);
}
dt.draw();
}

Expand Down Expand Up @@ -377,7 +422,16 @@
*/
function updateFilterResults (dt) {
var ctx = dt.settings()[0];
var filteredRows = dt.rows({"page": "current", "search": "applied"}).flatten().length;
var filteredRows;

if (ctx.oInit.serverSide) {
dt.on('draw', function () {
filteredRows = dt.ajax.json().recordsFiltered;
ctx._pfFilter.filterResults.html(filteredRows + " Results");
});
} else {
filteredRows = dt.rows({ "page": "current", "search": "applied" }).flatten().length;
}
if (ctx._pfFilter.filterResults === undefined || ctx._pfFilter.filterResults.length === 0) {
return;
}
Expand Down
14 changes: 13 additions & 1 deletion src/less/table-view.less
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ table.dataTable {
margin-bottom: 0;
}
}

}

// Inline action button and kebab
Expand All @@ -165,6 +164,10 @@ table.dataTable {
height: 100%;
width: 100%;
}
.table-view-pf-save,
.table-view-pf-cancel {
width: 50%;
}
.dropdown,
.table-view-pf-btn {
height: 100%;
Expand All @@ -177,6 +180,15 @@ table.dataTable {
}
}

// Inline edit td
.table-view-pf-editable > .table-view-pf-editor {
width: 100%;
color: @color-pf-black;
.filter-option {
color: @color-pf-black;
}
}

// Selection column
.table-view-pf-select {
width: 33px;
Expand Down
14 changes: 13 additions & 1 deletion src/sass/converted/patternfly/_table-view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ table.dataTable {
margin-bottom: 0;
}
}

}

// Inline action button and kebab
Expand All @@ -165,6 +164,10 @@ table.dataTable {
height: 100%;
width: 100%;
}
.table-view-pf-save,
.table-view-pf-cancel {
width: 50%;
}
.dropdown,
.table-view-pf-btn {
height: 100%;
Expand All @@ -177,6 +180,15 @@ table.dataTable {
}
}

// Inline edit td
.table-view-pf-editable > .table-view-pf-editor {
width: 100%;
color: $color-pf-black;
.filter-option {
color: $color-pf-black;
}
}

// Selection column
.table-view-pf-select {
width: 33px;
Expand Down
35 changes: 35 additions & 0 deletions src/sass/converted/rcue/_date-and-time.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Date and Time
// --------------------------------------------------
.date-time-picker-pf .input-group-addon {
.fa,
.pficon {
width: 12px;
}
}

.date-time-range-picker-pf {
.form-control,
.form-control:not(:first-child):not(:last-child) {
border-radius: $border-radius-base;
}
.form-control:first-child {
border-bottom-right-radius: $border-radius-base;
border-top-right-radius: $border-radius-base;
}
.form-control:last-child {
border-bottom-left-radius: $border-radius-base;
border-top-left-radius: $border-radius-base;
}
.input-group-addon {
background-color: transparent;
border: none;
line-height: $line-height-base;
padding: $padding-base-vertical $padding-base-horizontal;
}
.dropdown-kebab-pf {
float: right;
margin-left: 0;
margin-right: -15px;
}
}
86 changes: 86 additions & 0 deletions src/sass/converted/rcue/_list-view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,89 @@
position: relative;
width: 100%;
}
.list-view-pf-editable {
&.active,
&.list-view-pf-create {
.list-view-pf-editor,
.list-view-pf-editor.bootstrap-select,
.bootstrap-switch,
.list-view-pf-actions .list-view-pf-save,
.list-view-pf-actions .list-view-pf-cancel {
display: initial;
}
.list-view-pf-edit,
.list-view-pf-value:not(.list-view-pf-readonly),
.dropdown-kebab-pf {
display: none;
}
}
.list-view-pf-editor,
.list-view-pf-editor.bootstrap-select,
.bootstrap-switch,
.list-view-pf-actions .list-view-pf-save,
.list-view-pf-actions .list-view-pf-cancel {
display: none;
}
&.active {
.list-view-pf-additional-info {
@media (min-width: $screen-sm-min) {
margin-top: ($grid-gutter-width/2);
}
@media (min-width: $screen-md-min) {
margin-top: 0;
}
.list-view-pf-additional-info-item {
margin-top: ($grid-gutter-width/2);
@media (min-width: $screen-sm-min) {
margin-top: 0;
}
}
}
}
.list-view-pf-textbox {
margin-right: ($grid-gutter-width/2);
width: 100%;
}
.list-view-pf-readonly {
color: $color-pf-black-500;
}
.list-view-pf-actions {
margin: ($grid-gutter-width/4) 0;
width: 100px;
text-align: right;
.list-view-pf-save,
.list-view-pf-cancel {
font-size: $font-size-h1;
@media (max-width: $screen-sm-min) {
margin-left: 0;
}
}
}
.list-view-pf-description {
flex: 100%;
@media (min-width: $screen-sm-min) {
flex: 100%;
}
@media (min-width: $screen-md-min) {
flex: 25%;
}
}
.list-view-pf-additional-info {
flex: 100%;
.list-view-pf-additional-info-item {
flex: 100%;
}
@media (min-width: $screen-sm-min) {
flex: 100%;
.list-view-pf-additional-info-item {
flex: 1;
}
}
@media (min-width: $screen-md-min) {
flex: 75%;
.list-view-pf-additional-info-item {
flex: 1;
}
}
}
}
1 change: 1 addition & 0 deletions src/sass/converted/rcue/_patternfly-additions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
@import 'close';
@import 'context-selector';
@import 'datatables';
@import 'date-and-time';
@import 'experimental-features';
@import 'filter';
@import 'footer';
Expand Down
14 changes: 13 additions & 1 deletion src/sass/converted/rcue/_table-view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ table.dataTable {
margin-bottom: 0;
}
}

}

// Inline action button and kebab
Expand All @@ -165,6 +164,10 @@ table.dataTable {
height: 100%;
width: 100%;
}
.table-view-pf-save,
.table-view-pf-cancel {
width: 50%;
}
.dropdown,
.table-view-pf-btn {
height: 100%;
Expand All @@ -177,6 +180,15 @@ table.dataTable {
}
}

// Inline edit td
.table-view-pf-editable > .table-view-pf-editor {
width: 100%;
color: $color-pf-black;
.filter-option {
color: $color-pf-black;
}
}

// Selection column
.table-view-pf-select {
width: 33px;
Expand Down
15 changes: 15 additions & 0 deletions src/sass/converted/rcue/_time-picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
// Time Picker
// --------------------------------------------------
.bootstrap-datetimepicker-widget {
.today-button-pf:before {
content: "Today";
}
&.timepicker-sbs {
.datepicker, .accordion-toggle {
border-right: 1px solid $color-pf-black-300;
}
.timepicker {
padding-left: 0;
margin-top: 50px;
}
.picker-switch {
width: 50%;
}
}
a[data-action] {
border: 0;
box-shadow: none;
Expand Down