1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery tablesorter 2.0 - Filter Widget + jQuery UI Selectmenu</title>
<!-- jQuery -->
<script src="js/jquery-latest.min.js"></script>
<!-- Demo stuff -->
<link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
<script src="js/jquery-ui.min.js"></script>
<link rel="stylesheet" href="css/jq.css">
<link href="css/prettify.css" rel="stylesheet">
<script src="js/prettify.js"></script>
<script src="js/docs.js"></script>
<style>
th { width: 50%; }
</style>
<!-- Tablesorter: required -->
<link rel="stylesheet" href="../css/theme.blue.css">
<script src="../js/jquery.tablesorter.js"></script>
<script src="../js/widgets/widget-filter.js"></script>
<script id="js">$( function() {
// modified from http://jqueryui.com/selectmenu/#custom_render
$.widget( 'custom.iconselectmenu', $.ui.selectmenu, {
_renderItem: function( ul, item ) {
var hasClass,
li = $( '<li>' ),
wrapper = $( "<div>", {
// empty strings don't work, pass a
text: item.label || '\xA0'
});
if ( item.disabled ) {
li.addClass( 'ui-state-disabled' );
}
hasClass = item.element.attr( 'data-class' );
$( '<span>', {
style : item.element.attr( 'data-style' ),
'class' : hasClass ? 'ui-icon ' + item.element.attr( 'data-class' ) : ''
})
.appendTo( wrapper );
return li.append( wrapper ).appendTo( ul );
}
});
var $table = $( '#table' ),
selectmenuClass = 'selectmenu';
// reinitialize on "updateComplete" just-in-case an "updateAll" was called
$table.bind( 'tablesorter-initialized updateComplete', function() {
$table
.find( '.' + selectmenuClass )
.iconselectmenu({
change: function() {
// start a new search
$table.trigger( 'search' );
}
})
.iconselectmenu( 'menuWidget' )
.addClass( 'ui-menu-icons customicons' );
});
$table.tablesorter({
theme : 'blue',
widthFixed : true,
widgets : [ 'zebra', 'filter' ],
ignoreCase : false,
widgetOptions : {
// add 'selectmenu' class name to first filter
filter_cssFilter: [ selectmenuClass ],
filter_selectSource : {
0 : [
{ value : '/\\.js$/', 'data-class' : 'ui-icon-script', text : 'javascript' },
{ value : '/\\.(jpg|png|gif)$/', 'data-class' : 'ui-icon-image', text : 'Image' },
// plain strings are also acceptable - the string is added to both the text & value attribute
// 'foobar',
{ value : '.css', 'data-class' : 'ui-icon-note', text : 'CSS' },
{ value : '.html', 'data-class' : 'ui-icon-document', text : 'HTML page' },
{ value : '/\\.(json|txt|md)$/', 'data-class' : 'ui-icon-help', text : 'Misc' }
]
}
}
});
});</script>
</head>
<body>
<div id="banner">
<h1>table<em>sorter</em></h1>
<h2>Filter Widget + jQuery UI Selectmenu</h2>
<h3>Flexible client-side table sorting</h3>
<a href="index.html">Back to documentation</a>
</div>
<div id="main">
<p class="tip">
<em>NOTE!</em>
</p>
<ul>
<li>Updated <span class="version">v2.28.12</span>:
<ul>
<li>Fix issue with the selectmenu rendering with jQuery UI v1.12.1.</li>
<li>Fixed a filter widget issue with regular expression settings being ignored since select filters are set to exactly match the content (modified in <span class="version">v2.25.4</span>)</li>
<li><span class="label warning">*NOTE*</span> "filter-match" *must* be added to header since the default select behavior is to exactly match settings and this demo uses a combination of select value using partial matches and regular expressions.</li>
</ul>
</li>
<li>Demo added <span class="version">v2.24.4</span>, to demonstrate how to use <a href="http://jqueryui.com/selectmenu/#custom_render">jQuery UI Selectmenu widget</a> on a filter row select.</li>
<li><span class="label warning">*NOTE*</span> - Selectmenu will not work properly in all circumstances:
<ul>
<li>When an "updateAll" method is triggered on the table, the filter row is removed & replaced due to the possibility of a column being added or removed. Selectmenu initialization will need to be performed again.</li>
<li>If using selectmenu along with a widget that constantly removes & rebuilds extra table headers & filter rows (e.g. the scroller widget), the selectmenu initialization will need to be performed again, or just avoid using those widgets.</li>
</ul>
</li>
</ul>
<h1>Demo</h1>
<div id="demo">
<table id="table" class="tablesorter">
<thead>
<tr>
<th class="filter-select filter-match">File Name</th>
<th>Updated</th>
</tr>
</thead>
<tbody>
<tr><td>jquery.js</td><td>11/5/2015</td></tr>
<tr><td>jquery-ui.js</td><td>11/5/2015</td></tr>
<tr><td>map.jpg</td><td>10/22/2015</td></tr>
<tr><td>tooltips.js</td><td>8/5/2015</td></tr>
<tr><td>jquery-ui.css</td><td>11/5/2015</td></tr>
<tr><td>index.html</td><td>11/9/2015</td></tr>
<tr><td>smiley.gif</td><td>8/14/2015</td></tr>
<tr><td>demo.html</td><td>11/7/2015</td></tr>
<tr><td>theme.blue.css</td><td>10/17/2015</td></tr>
<tr><td>tablesorter.js</td><td>11/9/2015</td></tr>
<tr><td>readme.md</td><td>11/9/2015</td></tr>
<tr><td>package.json</td><td>11/8/2015</td></tr>
<tr><td>contributions.md</td><td>10/8/2015</td></tr>
<tr><td>license.txt</td><td>10/2/2015</td></tr>
<tr><td>logo.png</td><td>11/1/2015</td></tr>
</tbody>
</table></div>
<h1>Page Header</h1>
<div>
<pre class="prettyprint lang-html"><!-- jQuery & jQuery UI -->
<link rel="stylesheet" href="css/jquery-ui.min.css">
<script src="js/jquery-latest.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<!-- tablesorter plugin -->
<link rel="stylesheet" href="css/theme.blue.css">
<script src="js/jquery.tablesorter.js"></script>
<!-- tablesorter filter widget - loaded after the plugin -->
<script src="/js/widgets/widget-filter.js"></script></pre>
</div>
<h1>Javascript</h1>
<div id="javascript">
<pre class="prettyprint lang-javascript"></pre>
</div>
<h1>HTML</h1>
<div id="html">
<pre class="prettyprint lang-html"></pre>
</div>
</div>
</body>
</html>
|