Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix of issue http://github.com/gregwebs/jquery-uitablefilter/issues/#…

…issue/2;

make selection of filtered row more accurate; added testtable which shows the problem from issue 2; added tests for normal filtering and for filtering with inner tables (issue 2)
  • Loading branch information...
commit 6d9df6be4bf0c56179bcd9fdc1643717ea6ea309 1 parent b119c6d
@barclay-reg barclay-reg authored
Showing with 170 additions and 2 deletions.
  1. +2 −2 jquery.uitablefilter.js
  2. +168 −0 test/ui_table_filter_spec.html
View
4 jquery.uitablefilter.js
@@ -56,11 +56,11 @@
// only hide visible rows
matches = function(elem) {;}
- var elems = jq.find("tbody > tr:visible")
+ var elems = jq.find("tbody:first > tr:visible")
}
else {
new_hidden = true;
- var elems = jq.find("tbody > tr")
+ var elems = jq.find("tbody:first > tr")
}
elems.each(function(){
View
168 test/ui_table_filter_spec.html
@@ -46,6 +46,139 @@
}
})
+describe('filterNormalTable', {
+ before_all : function(){
+ var theTable = $("#testtable")
+ filter = function(pattern) {
+ $.uiTableFilter( theTable, pattern, 0 );
+ }
+
+ resetFilter = function(){
+ filter('');
+ }
+ },
+
+ after_each : function(){
+ resetFilter();
+ },
+
+ 'no filter, all rows must be visible' : function(){
+
+ filter('')
+ value_of($('#headrow:visible').html()).should_be($('#headrow').html())
+ value_of($('#testrow1:visible').html()).should_be($('#testrow1').html())
+ value_of($('#testrow2:visible').html()).should_be($('#testrow2').html())
+ },
+
+ 'simple filter 1' : function(){
+
+ filter('turtle')
+ value_of($('#headrow:visible').html()).should_be($('#headrow').html())
+ value_of($('#testrow1:visible').html()).should_be($('#testrow1').html())
+ value_of($('#testrow2:visible').html()).should_be_null()
+ },
+
+ 'simple filter 2' : function(){
+
+ filter('dog')
+ value_of($('#headrow:visible').html()).should_be($('#headrow').html())
+ value_of($('#testrow1:visible').html()).should_be($('#testrow1').html())
+ value_of($('#testrow2:visible').html()).should_be_null()
+ },
+
+ 'simple filter 3' : function(){
+
+ filter('whale')
+ value_of($('#headrow:visible').html()).should_be($('#headrow').html())
+ value_of($('#testrow1:visible').html()).should_be_null()
+ value_of($('#testrow2:visible').html()).should_be($('#testrow2').html())
+ },
+
+ 'simple head filter (head must still be visible)' : function(){
+
+ filter('sea')
+ value_of($('#headrow:visible').html()).should_be($('#headrow').html())
+ value_of($('#testrow1:visible').html()).should_be_null()
+ value_of($('#testrow2:visible').html()).should_be_null()
+ } ,
+
+ 'simple filter an resetFilter' : function(){
+ filter('turtle')
+ value_of($('#headrow:visible').html()).should_be($('#headrow').html())
+ value_of($('#testrow1:visible').html()).should_be($('#testrow1').html())
+ value_of($('#testrow2:visible').html()).should_be_null()
+ filter('')
+ value_of($('#headrow:visible').html()).should_be($('#headrow').html())
+ value_of($('#testrow1:visible').html()).should_be($('#testrow1').html())
+ value_of($('#testrow2:visible').html()).should_be($('#testrow2').html())
+ }
+})
+
+
+describe('filterInnerTable', {
+ before_all : function(){
+ var theTable = $("#testtable2")
+ filter = function(pattern) {
+ $.uiTableFilter( theTable, pattern, 0 );
+ }
+
+ resetFilter = function(){
+ filter('');
+ }
+ },
+
+ after_each : function(){
+ resetFilter();
+ },
+
+ 'no filter, all rows must be visible' : function(){
+
+ filter('')
+ value_of($('#headrow2:visible').html()).should_be($('#headrow2').html())
+ value_of($('#testrow2.1:visible').html()).should_be($('#testrow2.1').html())
+ value_of($('#testrow2.2:visible').html()).should_be($('#testrow2.2').html())
+ value_of($('#innerHeadRow:visible').html()).should_be($('#innerHeadRow').html())
+ value_of($('#innerRow1:visible').html()).should_be($('#innerRow1').html())
+ value_of($('#innerRow2:visible').html()).should_be($('#innerRow2').html())
+ },
+
+
+ 'filter for non existing value' : function(){
+
+ filter('blaBlubb')
+ value_of($('#headrow2:visible').html()).should_be($('#headrow2').html())
+ value_of($('#testrow2.1:visible').html()).should_be($('#testrow2.1').html())
+ value_of($('#testrow2.2:visible').html()).should_be_null()
+ value_of($('#innerHeadRow:visible').html()).should_be($('#innerHeadRow').html())
+ value_of($('#innerRow1:visible').html()).should_be($('#innerRow1').html())
+ value_of($('#innerRow2:visible').html()).should_be($('#innerRow2').html())
+ },
+
+ 'filter for existing value (complete inner table must disappear)' : function(){
+
+ filter('whale')
+ value_of($('#headrow2:visible').html()).should_be($('#headrow2').html())
+ value_of($('#testrow2.1:visible').html()).should_be_null()
+ value_of($('#testrow2.2:visible').html()).should_be_null()
+ value_of($('#innerHeadRow:visible').html()).should_be($('#innerHeadRow').html())
+ value_of($('#innerRow1:visible').html()).should_be($('#innerRow1').html())
+ value_of($('#innerRow2:visible').html()).should_be($('#innerRow2').html())
+ },
+
+ 'filter for existing value which is in the inner table (all rows should disappear, but inner table should be (theoreticaly) visible)' : function(){
+
+ filter('turtle')
+ value_of($('#headrow2:visible').html()).should_be($('#headrow2').html())
+ value_of($('#testrow2.1:visible').html()).should_be($('#testrow2.1').html())
+ value_of($('#testrow2.2:visible').html()).should_be_null()
+ value_of($('#innerHeadRow:visible').html()).should_be($('#innerHeadRow').html())
+ value_of($('#innerRow1:visible').html()).should_be($('#innerRow1').html())
+ value_of($('#innerRow2:visible').html()).should_be($('#innerRow2').html())
+ }
+
+
+})
+
// ]]></script>
</head>
<body>
@@ -67,6 +200,41 @@
<tr id="testrow2"> <td>whale</td><td>monkey</td> </tr>
</tbody>
</table>
+
+ <table id="testtable2">
+ <thead id="testhead2">
+ <tr id="headrow2"> <th>sea</th><th>land</th> </tr>
+ </thead>
+ <tbody>
+ <tr id="testrow2.1">
+ <td>turtle</td>
+ <td>
+ <table id="innerTable">
+ <thead id="innerHead">
+ <tr id="innerHeadRow">
+ <th>innerHead1 mine</th>
+ <th>innerHead2 yours</th>
+ </tr>
+ </thead>
+ <tbody id="innerBody">
+ <tr id="innerRow1">
+ <td>innerRow1.1 duck turtle</td>
+ <td>innerRow1.2 horse</td>
+ </tr>
+ <tr id="innerRow2">
+ <td>innerRow2.1 cat</td>
+ <td>innerRow2.2 dog</td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ <tr id="testrow2.2">
+ <td>whale</td>
+ <td>monkey</td>
+ </tr>
+ </tbody>
+ </table>
</div>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.