@@ -38,6 +38,9 @@ <h1>Here's where I keep a list of papers I have read.</h1>
38
38
< p id ="paperCount ">
39
39
So far, we have read 0 papers. Let's keep it up!
40
40
</ p >
41
+ < small id ="searchCount ">
42
+ your search returned 0 papers. nice!
43
+ </ small >
41
44
42
45
< div class ="search-inputs ">
43
46
< input type ="text " id ="titleSearch " placeholder ="Search title... ">
@@ -79,6 +82,7 @@ <h1>Here's where I keep a list of papers I have read.</h1>
79
82
description : document . getElementById ( 'descriptionSearch' )
80
83
} ;
81
84
const paperCountElement = document . getElementById ( 'paperCount' ) ;
85
+ const searchCountElement = document . getElementById ( 'searchCount' ) ;
82
86
let sortOrder = { } ;
83
87
84
88
// Load papers from JSON file
@@ -87,6 +91,8 @@ <h1>Here's where I keep a list of papers I have read.</h1>
87
91
. then ( papers => {
88
92
populateTable ( papers ) ;
89
93
updatePaperCount ( papers . length ) ;
94
+ // set search count as paper count initially
95
+ updateSearchCount ( papers . length ) ;
90
96
setupEventListeners ( ) ;
91
97
} )
92
98
. catch ( error => console . error ( 'Error loading papers:' , error ) ) ;
@@ -118,6 +124,9 @@ <h1>Here's where I keep a list of papers I have read.</h1>
118
124
function updatePaperCount ( count ) {
119
125
paperCountElement . textContent = `So far, we have read ${ count } papers. Let's keep it up!` ;
120
126
}
127
+ function updateSearchCount ( count ) {
128
+ searchCount . textContent = `your search returned ${ count } papers. nice!` ;
129
+ }
121
130
122
131
function setupEventListeners ( ) {
123
132
for ( let key in searchInputs ) {
@@ -143,6 +152,7 @@ <h1>Here's where I keep a list of papers I have read.</h1>
143
152
144
153
function searchTable ( ) {
145
154
const rows = tbody . getElementsByTagName ( 'tr' ) ;
155
+ var numRowsMatch = 0 ;
146
156
for ( let i = 0 ; i < rows . length ; i ++ ) {
147
157
const row = rows [ i ] ;
148
158
const cells = row . getElementsByTagName ( 'td' ) ;
@@ -157,8 +167,14 @@ <h1>Here's where I keep a list of papers I have read.</h1>
157
167
}
158
168
}
159
169
160
- row . style . display = foundMatch ? '' : 'none' ;
170
+ if ( foundMatch ) {
171
+ row . style . display = ''
172
+ numRowsMatch ++ ;
173
+ } else {
174
+ row . style . display = 'none'
175
+ }
161
176
}
177
+ updateSearchCount ( numRowsMatch )
162
178
}
163
179
164
180
function sortTable ( column , dataType , order ) {
0 commit comments