SearchBuilder String "Subtype"

SearchBuilder String "Subtype"

NessalcNessalc Posts: 3Questions: 2Answers: 0

Description of problem:
I would like to update the SearchBuilder conditions for one column, changing the names of those conditions and removing the other conditions. I defined the column (in relevant part) this way:

{
    data: 'cycle',
    type: 'string',
    searchBuilderType: 'cycle'
},

When I create a custom condition using this to change only the names:

cycle: {
    'contains': {
        conditionName: 'Includes'
    },
    '!contains': {
        conditionName: 'Does Not Include'
    }
},

This removes the extra conditions and changes the titles of these, but when I select either option, there is no input box allowing me to specify what to search for.

If, on the other hand, I leave the searchBuilderType alone on the column definition and change cycle in the condition to string, the name is changed on all the string columns in my dataset, and the other options are still there. I can remove those by adding lines like '='=null, but that doesn't accomplish my end goal.

My question is this: do I have to redefine init, inputValue, isInputValid, and search here (digging through the source and copying is not as straightforward as I'd hoped) because I only want this change to apply to a single column? Can I somehow define cycle as a subtype of string for this purpose?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,507Questions: 1Answers: 10,660 Site admin
    Answer ✓

    do I have to redefine init, inputValue, isInputValid, and search here

    Yes. At the moment contains is just an object with conditionName and SearchBuilder doesn't fallback to the string option (or anything else) if it isn't found in the given object (although that is a good idea, I might implement that when I get around to rewriting SeachBuilder).

    So you can't define a subtype. However, it is fairly easy to just copy the options across:

    DataTable.ext.searchBuilder.conditions['cycle'] = {
      contains: Object.assign({}, DataTable.Criteria.stringConditions.contains, {
        conditionName: 'Includes'
      },
      '!contains': ...
    };
    

    Allan

  • NessalcNessalc Posts: 3Questions: 2Answers: 0

    Thank you! I feel very silly now, as I had

    init: Criteria.initInput,
    

    instead of

    init: DataTable.Criteria.initInput,
    

    and thought I was going to have to copy a lot more code over!

  • allanallan Posts: 64,507Questions: 1Answers: 10,660 Site admin

    Hah - yes, that would be scary! I think that is an area which can definitely be improved. I've made a note of it for when I give SearchBuilder an overhaul.

    Allan

Sign In or Register to comment.