Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Tags filtering" functionality #163

Open
fromaline opened this issue Sep 27, 2023 · 0 comments
Open

"Tags filtering" functionality #163

fromaline opened this issue Sep 27, 2023 · 0 comments

Comments

@fromaline
Copy link

First off, great library! I use it for my project and it gets work done really good 馃檹

I encountered a use case where I need to implement tags for the table. It's a row of buttons above the table with common filters.
For example, if table shows users data, the tags could be "Man" and "Woman".

It's pretty ease to emplement using built in writable primitive:

<script lang="ts">
  const activeTag: 'man' | 'woman' | 'none' = 'none'

  const tableData = writable(data)

  const table = createTable(tableData)

  $: if (activeTag === 'man') {
    tableData.set(data.filter(person => person.gender === 'man'))
  } else if (activeTag === 'woman') {
    tableData.set(data.filter(person => person.gender === 'woman'))
  } else if (activeTag === 'none') {
    tableData.set(data)
  }
</script>

<div>
  <button 
    on:click={() => {
      if (activeTag === 'none') {
        activeTag = 'man'
      } else if (activeTag === 'woman') {
        activeTag = 'man'
      } else if (activeTag === 'man') {
        activeTag = 'none'
      }
    }}
    class:active={activeTag === 'man'}
  >
    Man
  </button>

  <button 
    on:click={() => {
      if (activeTag === 'none') {
        activeTag = 'woman'
      } else if (activeTag === 'man') {
        activeTag = 'woman'
      } else if (activeTag === 'woman') {
        activeTag = 'none'
      }
    }}
    class:active={activeTag === 'woman'}
  >
    Woman
  </button>
</div>

<table {...$tableAttrs}>
  <!-- other stuff -->
</table>

But it would be really cool if there was a plugin for it. I imagine it like that:

<script lang="ts">
  const activeTag: 'man' | 'woman' | 'none' = 'none'

  const tableData = writable(data)

  const table = createTable(tableData, {
    tagFiltering: addTagFiltering({
      fn: (prevData) => {
        if (activeTag === 'man') {
          return data.filter(person => person.gender === 'man')
        } else if (activeTag === 'woman') {
          return data.filter(person => person.gender === 'woman')
        } else if (activeTag === 'none') {
          return data
        }
      }
    })
  })
</script>

Do you think it worth implementing? Or is it waste of time?

@fromaline fromaline changed the title "Tag" functionality "Tags filtering" functionality Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant