vincjo / datatables

A toolkit for creating datatable components with Svelte
https://vincjo.fr/datatables
MIT License
363 stars 15 forks source link

filter nested tables, does not hide items inside the nested table #86

Closed Conni2461 closed 1 month ago

Conni2461 commented 5 months ago

Hey, first of all thanks for your awesome project. I really love it. I just have one minor issue with nested tables.

If you e.g. look at https://vincjo.fr/datatables/examples/nested-objects which has a nested car table, and then start filtering for "pt cru" i expect the nested table also to be filtered. So it should result in following table, where everything that is marked as blue blocks is no longer shown (image 2). Currently it looks like this (image 1).

image image

Is this currently possible, or does this require changes/stuff here. If yes i would also be open to contributing these changes, if you are interested.

vincjo commented 5 months ago

Hey, thx for your suggestion. I understand your point but can't figure out how we could achieve this.

For now I just added:

if ($filters.length > 0) {
    $filters.forEach((filter) => {
        return ($rawRows = $rawRows.filter((row) => {
            const entry = filter.callback(row)
+            if (filter.identifier === 'car' && row['car']) {
+                row['car'] = row['car'].filter(item => {
+                    return this.match(item, filter.value, filter.comparator)
+                })
+            }
            return this.match(entry, filter.value, filter.comparator)
        }))
    })
    this.pageNumber.set(1)
    this.selected.set([])
    this.event.trigger('change')
}
return $rawRows

in /lib/local/Context.ts createFilteredRows() line 76

It works fine on "car" nested array but the initial values are erased after removing the filter.

vincjo commented 1 month ago

98