@@ -169,10 +169,10 @@ export default {
169
169
170
170
computed: {
171
171
tableContent () {
172
- if (this .copy .content && this . copy . content . length > 0 ) {
173
- return this .copy .content
172
+ if (this .copy .content === null ) {
173
+ return this .file .content
174
174
}
175
- return this .file .content
175
+ return this .copy .content
176
176
},
177
177
tableColumns () {
178
178
if (this .copy .content && this .copy .content .length > 0 ) {
@@ -204,7 +204,13 @@ export default {
204
204
return columns
205
205
},
206
206
totalNumberOfPages () {
207
- return Math .ceil (this .tableContent .length / this .page .limit )
207
+ const numberOfPages = Math .ceil (this .tableContent .length / this .page .limit )
208
+
209
+ if (numberOfPages === 0 ) {
210
+ return 1
211
+ }
212
+
213
+ return numberOfPages
208
214
},
209
215
isOnLastPage () {
210
216
return this .page .currentPage === this .totalNumberOfPages
@@ -246,29 +252,77 @@ export default {
246
252
}
247
253
},
248
254
filterData () {
249
- this .setCopyContent ()
255
+ if (Object .keys (this .filters ).length === 0 ) {
256
+ this .copy .content = null
257
+ this .saveFile ()
258
+ return
259
+ }
260
+
261
+ let data = this .file .content .map ((row ) => {
262
+ return {... row}
263
+ })
264
+
265
+ const copyFilters = []
266
+
267
+ for (const rowIndex in data) {
268
+ const row = data[rowIndex]
269
+ const passedFilters = []
270
+ for (const filterKey in this .filters ) {
271
+ if (this .filters [filterKey].type === ' file' ) {
272
+ const columnToString = row[filterKey]? .toString ().toUpperCase ()
273
+ if (columnToString && this .filters [filterKey].values .some (item => this .checkFilterValues (item, columnToString))) {
274
+ passedFilters .push (true )
275
+ } else {
276
+ passedFilters .push (false )
277
+ }
278
+ } else {
279
+ if (copyFilters .indexOf (filterKey) === - 1 ) {
280
+ copyFilters .push (filterKey)
281
+ }
282
+ }
283
+ }
250
284
251
- for (const key in this .filters ) {
252
- this .copy .content = this [this .filters [key].type ].content .filter ((row ) => {
253
- const rowKeyToString = row[key]? .toString ().toUpperCase ().split (' ' )
254
- if (rowKeyToString && this .filters [key].values .some ((item ) => {
255
- if (item .includes (' "' )) {
256
- return rowKeyToString .includes (item .trim ().replaceAll (' "' , ' ' ).toUpperCase ())
285
+ if (! passedFilters .includes (true )) {
286
+ delete data[rowIndex]
287
+ }
288
+ }
289
+
290
+ data .filter (Boolean )
291
+
292
+ if (copyFilters .length > 0 ) {
293
+ for (const rowIndex in data) {
294
+ const row = data[rowIndex]
295
+ let copy = true
296
+ for (const filter of copyFilters) {
297
+ const columnToString = row[filter]? .toString ().toUpperCase ()
298
+ if (copy && columnToString && this .filters [filter].values .some (item => this .checkFilterValues (item, columnToString))) {
299
+ // continue
257
300
} else {
258
- return rowKeyToString . find ( a => a . includes ( item . trim (). toUpperCase ()))
301
+ copy = false
259
302
}
260
- })) {
261
- return row
262
303
}
263
- return false
264
- })
304
+
305
+ if (! copy) {
306
+ delete data[rowIndex]
307
+ }
308
+ }
265
309
}
266
310
311
+ this .copy .content = data .filter (Boolean )
312
+
267
313
this .saveFile ()
268
314
},
315
+ checkFilterValues (item , columnValue ) {
316
+ const query = columnValue
317
+ if (item .includes (' "' )) {
318
+ return query .includes (item .trim ().replaceAll (' "' , ' ' ).toUpperCase ())
319
+ } else {
320
+ return query .split (' ' ).find (a => a .includes (item .trim ().toUpperCase ()))
321
+ }
322
+ },
269
323
removeFilter (key ) {
270
324
delete this .filters [key]
271
- this .copy .content = this . file . content
325
+ this .copy .content = null
272
326
this .filterData ()
273
327
},
274
328
loadFileContent () {
0 commit comments