Custom Search Builder and boolean values

Custom Search Builder and boolean values

GerritKuilderGerritKuilder Posts: 6Questions: 2Answers: 0

Hello All,

first of all I think this is a great product and helps me a lot, still have a few things to learn but one one the things that I have not been able to manage to do is use the the Custom Search Builder with boolean values. In my table I have various boolean values (which I currently output with icons).
I would like to be able to use the boolean value in the Custom Search Builder to filter true/false values.
I have tried it with just outputting the value and try to filter on that, without luck. I am building the table from an Ajax source, getting it from a table.
I have been searching a lot on this issue for a week or so, I hope someone is able to show me a basic example.

Maybe worth adding to the examples.

Looking forward to replies/ideas.

Kind regards,

Gerrit Kuilder

This question has an accepted answers - jump to answer

Answers

  • sandysandy Posts: 399Questions: 0Answers: 112

    Hi @GerritKuilder ,

    SearchBuilder ships as standard with conditions for all of the columns.type that DataTables is able to auto detect. Boolean is not one of these types.

    It is however possible to declare your own conditions for a custom type, take a look at this example. For a boolean column type you would do something like this...

    $.fn.dataTable.ext.searchBuilder.conditions.boolean = {
        'true': {
            conditionName: function (dt, i18n) { return 'True'; },
            isInputValid: function () { return true; },
            init: function () { return; },
            inputValue: function () { return; },
            search: function (value) { return value === 'true'; },
        },
        'false': {
            conditionName: function (dt, i18n) { return 'False'; },
            isInputValid: function () { return false; },
            init: function () { return; },
            inputValue: function () { return; },
            search: function (value) { return value === 'false'; },
        },
    }
    

    ...as well as setting a custom column type of boolean.

    BUT, you are using icons as the boolean values, so the above will not work for that use case. We've had a brief chat about this and we think that we need to add an orthogonal option to SearchBuilder, a bit like SearchPanes does with columns.searchpanes.orthogonal. I've raised an issue internally (DD-1727 for my reference) and will report back here when there is an update.

    In the mean time I suppose there are one or two hacky ways that you could solve this until we get a proper fix. The two obvious paths forwards that I can see would be to either add a hidden column, with simple true/false string values that SearchBuilder can filter on. The second would be to see what the value of value is in the search function above. It may be that you can filter using that.

    Thanks,
    Sandy

  • GerritKuilderGerritKuilder Posts: 6Questions: 2Answers: 0

    Hi @sandy ,

    thank you for your answer, I ended up at that table a few times but could not see how it would apply to boolean values. I looked a bit closer and think I can figure it by now.
    I will see if I can implement it over the coming few days and will let you know.
    I think a boolean column type would be most welcome. if a td class or value="" can be used for picking up the value the output in the column can be very flexible.

    Kind regards,

    Gerrit Kuilder

  • sandysandy Posts: 399Questions: 0Answers: 112
    Answer ✓

    Hi @GerritKuilder ,

    Just to let you know that we have now added an orthogonal option to SearchBuilder. This will be available in the next SearchBuilder release which we hope will be in the next few weeks. Until then you can access the fix from the nightly builds.

    Take a look at this example to see a couple of ways it may work.

    Thanks,
    Sandy

  • GerritKuilderGerritKuilder Posts: 6Questions: 2Answers: 0

    Hi Sandy

    Thank you,

    bookmarked this link and will check back in a few weeks, busy with other projects now.

    Kind Regards,

    Gerrit Kuilder

Sign In or Register to comment.