Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
how to search in a table

I found this example related to a table created with sveltestrap. the problem that I can not solve, is to make the search insensitive houses and do not know how to do code tested with svelte REPL

    <script>
    import { onMount } from 'svelte';
    import { Card, CardBody, CardHeader, Input, Table, Column, Styles } from 'sveltestrap';
    
    let search = undefined;
    let users = [];
    $: visibleUsers = search ?
        users.filter(user => {
            return  user.name.first.match(`${search}.*`)  || user.name.last.match(`${search}.*`)
        }) : users;

    onMount(async () => {
        const resp = await fetch('https://randomuser.me/api?results=25&inc=id,name,email,')
        const data = await resp.json();
        users = data.results;
    });
</script>

    <style>
      @import url('https://gthomas-appfolio.github.io/bootstrap-coastline/bootstrap-coastline.css');
    </style>
    
    <Card>
        <CardHeader>
            <Input type="search" bind:value={search} class="ms-auto w-auto" placeholder="Search" />
        </CardHeader>
        <CardBody>
            <Table striped rows={visibleUsers} let:row={user}>
    <Column header="uuid">
                    {user.id.value}
                </Column>
                <Column header="First">
                    {user.name.first}
                </Column>
                <Column header="Last">
                    {user.name.last}
                </Column>
                <Column header="Email">
                    {user.email}
                </Column>
            </Table>
        </CardBody>
    </Card>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This code is using regular expressions to do the matching:

        users.filter(user => {
            return  user.name.first.match(`${search}.*`)  || user.name.last.match(`${search}.*`)
        }) : users;

Regular expressions can accept flags, one of which is "case insensitive" (the "i" flag). You can construct a regular expression dynamically by using the RegExp constructor; its second argument accepts flags.

So change the above code to something like this:

        users.filter(user => {
            const regex = new RegExp(`${search}.*`, 'i')
            return  user.name.first.match(regex)  || user.name.last.match(regex)
        }) : users;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda