Search each word individually

Search each word individually

ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1

Hello, i have a table with a column skills set up like this :

i would like when i use searchbuilder, that i can search each words individually (actualy the filter is like this, how i m suppose to do ?)

Thank for your time / answer

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Hi,

    This example shows how it can be done.

    If you need more help than that, could you give me a link to your page so I can see the configuration and data please?

    Thanks,
    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
    edited October 2023

    i see that in ur ajax, the data are set up with 2 value, an id and a name

    "permission": [
        {
          "id": "3",
          "name": "Desktop"
        },
        {
          "id": "1",
          "name": "Printer"
        },
        {
          "id": "4",
          "name": "VMs"
        }
      ]
    

    so the javascript is set up like this :

    {
                    data: "permission",
                    render: {
                        _: '[, ].name',
                        sb:'[].name'
                    },
                    searchBuilder: {
                        orthogonal:'sb'
                    },
                    searchBuilderType: 'array'
                }
    

    In my json, the data is only one value and not separate with { } :

    "SKILLS":"Skills1 , Skill 2"

    How i m suppose to set up my javascript ? Do i have to change my json as well to look like your ?

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    edited October 2023

    Change your columns.render to a function and return the sb Orthogonal data as an array. I didn't test it but try this:

    {
                  data: "SKILLS",
                  render: function ( data, type, row ) {
                    // Return an array for search builder
                    if ( type === 'sb' ) {
                        // Split the string to create an array of skills
                        return data.split( " , " );
                    }
                    // Otherwise return the original data for all other orthogonal types
                    return data;
                },
                    searchBuilder: {
                        orthogonal:'sb'
                    },
                    searchBuilderType: 'array'
                }
    

    Kevin

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    As you have it at the moment, the data is just a string, so it is correctly just displaying a list of the possible strings.

    Yes, if you want to use SearchBuilder's array based operations, you'd need to use an array for the data.

    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1

    Thank you, i change my json to use an array and now it work perfeclty ! :)

Sign In or Register to comment.