Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…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
barclay-reg committed Oct 23, 2010
1 parent b119c6d commit 6d9df6b
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jquery.uitablefilter.js
Expand Up @@ -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(){
Expand Down
168 changes: 168 additions & 0 deletions test/ui_table_filter_spec.html
Expand Up @@ -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>
Expand All @@ -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>

0 comments on commit 6d9df6b

Please sign in to comment.