From 46e6749a06a8ec543c0ba4283e86f0b8d54f2a33 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Thu, 31 Aug 2017 14:39:03 +0100 Subject: [PATCH] Adding search pane plug-in. Completely unfinished, but its a start! --- .../dataTables.searchHighlight.min.js | 4 +- features/searchPane/dataTables.searchPane.css | 88 +++ features/searchPane/dataTables.searchPane.js | 187 +++++++ .../searchPane/dataTables.searchPane.min.css | 1 + .../searchPane/dataTables.searchPane.min.js | 5 + .../searchPane/dataTables.searchPane.scss | 105 ++++ features/searchPane/index.html | 524 ++++++++++++++++++ 7 files changed, 912 insertions(+), 2 deletions(-) create mode 100644 features/searchPane/dataTables.searchPane.css create mode 100644 features/searchPane/dataTables.searchPane.js create mode 100644 features/searchPane/dataTables.searchPane.min.css create mode 100644 features/searchPane/dataTables.searchPane.min.js create mode 100644 features/searchPane/dataTables.searchPane.scss create mode 100644 features/searchPane/index.html diff --git a/features/searchHighlight/dataTables.searchHighlight.min.js b/features/searchHighlight/dataTables.searchHighlight.min.js index 3875871..bef7dda 100644 --- a/features/searchHighlight/dataTables.searchHighlight.min.js +++ b/features/searchHighlight/dataTables.searchHighlight.min.js @@ -2,5 +2,5 @@ SearchHighlight for DataTables v1.0.1 2014 SpryMedia Ltd - datatables.net/license */ -(function(h,g,b){function e(d,c){d.unhighlight();c.rows({filter:"applied"}).data().length&&d.highlight(b.trim(c.search()).split(/\s+/))}b(g).on("init.dt.dth",function(d,c){if("dt"===d.namespace){var a=new b.fn.dataTable.Api(c),f=b(a.table().body());if(b(a.table().node()).hasClass("searchHighlight")||c.oInit.searchHighlight||b.fn.dataTable.defaults.searchHighlight)a.on("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth",function(){e(f,a)}).on("destroy",function(){a.off("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth")}), -a.search()&&e(f,a)}})})(window,document,jQuery); +(function(h,g,a){function e(d,c){d.unhighlight();c.rows({filter:"applied"}).data().length&&(c.columns().every(function(){this.nodes().flatten().to$().unhighlight({className:"column_highlight"});this.nodes().flatten().to$().highlight(a.trim(this.search()).split(/\s+/),{className:"column_highlight"})}),d.highlight(a.trim(c.search()).split(/\s+/)))}a(g).on("init.dt.dth",function(d,c){if("dt"===d.namespace){var b=new a.fn.dataTable.Api(c),f=a(b.table().body());if(a(b.table().node()).hasClass("searchHighlight")|| +c.oInit.searchHighlight||a.fn.dataTable.defaults.searchHighlight)b.on("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth",function(){e(f,b)}).on("destroy",function(){b.off("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth")}),b.search()&&e(f,b)}})})(window,document,jQuery); diff --git a/features/searchPane/dataTables.searchPane.css b/features/searchPane/dataTables.searchPane.css new file mode 100644 index 0000000..574d0b0 --- /dev/null +++ b/features/searchPane/dataTables.searchPane.css @@ -0,0 +1,88 @@ +div.dt-searchPane { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: space-around; + align-content: flex-start; + align-items: stretch; + height: 100%; + margin: 1em 0; +} +div.dt-searchPane div.pane { + position: relative; + flex: 1; + margin: 0 0.5%; + border: 1px solid #ccc; + /*width: 15.5%; + margin: 0 0.583333333%;*/ +} +div.dt-searchPane div.pane button[type=button] { + display: none; +} +div.dt-searchPane div.pane.filtering button[type=button] { + display: block; + position: absolute; + right: 6px; + top: 6px; + border: 1px solid #999; + background: rgba(0, 0, 0, 0.1); + border-radius: 3px; + cursor: pointer; +} +div.dt-searchPane div.pane.filtering button[type=button]:hover { + background: rgba(0, 0, 0, 0.2); +} +div.dt-searchPane div.pane div.title { + box-sizing: border-box; + height: 30px; + padding: 0.35em; + font-size: 1.1em; + background-color: rgba(0, 0, 0, 0.075); + border-bottom: 1px solid #ddd; +} +div.dt-searchPane div.pane div.scroller { + position: absolute; + top: 30px; + bottom: 0; + left: 0; + right: 0; + overflow: auto; +} +div.dt-searchPane div.pane div.scroller ul { + list-style: none; + margin: 0; + padding: 0; +} +div.dt-searchPane div.pane div.scroller ul li { + position: relative; + margin: 0; + padding: 0; + cursor: pointer; +} +div.dt-searchPane div.pane div.scroller ul li:nth-child(odd) { + background: rgba(0, 0, 0, 0.03); +} +div.dt-searchPane div.pane div.scroller ul li.selected { + background: #3276b1; + color: white; +} +div.dt-searchPane div.pane div.scroller ul li span.label { + display: inline-block; + box-sizing: border-box; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + width: 85%; + vertical-align: middle; + padding: 0.2em 0.3em; +} +div.dt-searchPane div.pane div.scroller ul li span.count { + display: inline-block; + width: 14%; + margin-right: 1%; + font-size: 0.8em; + color: white; + text-align: center; + background-color: #3276b1; + border-radius: 3px; +} diff --git a/features/searchPane/dataTables.searchPane.js b/features/searchPane/dataTables.searchPane.js new file mode 100644 index 0000000..fd5a464 --- /dev/null +++ b/features/searchPane/dataTables.searchPane.js @@ -0,0 +1,187 @@ +// TODO +// - Tidy up class names +// - Clean up code into functions +// - Option to have vertical layout class +// - Number of horizontal panels class options +// - Threshold option - require that there is duplicate information in a column before it is used +// - Styling for selected +// - Styling for container / header +// - Styling for clear option +// - State saving integration + + +(function( factory ){ + if ( typeof define === 'function' && define.amd ) { + // AMD + define( ['jquery', 'datatables.net'], function ( $ ) { + return factory( $, window, document ); + } ); + } + else if ( typeof exports === 'object' ) { + // CommonJS + module.exports = function (root, $) { + if ( ! root ) { + root = window; + } + + if ( ! $ || ! $.fn.dataTable ) { + $ = require('datatables.net')(root, $).$; + } + + return factory( $, root, root.document ); + }; + } + else { + // Browser + factory( jQuery, window, document ); + } +}(function( $, window, document, undefined ) { +'use strict'; +var DataTable = $.fn.dataTable; + + +function SearchPanes ( settings, opts ) { + var that = this; + var table = new DataTable.Api( settings ); + var container = $('
') + .appendTo( opts.container ); + + table.columns(opts.columns).eq(0).each( function ( idx ) { + var column = table.column( idx ); + + var list = $('