savedStatesCreate - Predefined searchBuilder State

savedStatesCreate - Predefined searchBuilder State

Hon3yNutzHon3yNutz Posts: 13Questions: 3Answers: 0

I would like to create a public predefined state for all users. I see the example for both pulling and loading searchbuilder as well as predefined searchbuilder terms. It seems the predefined configuration item only allows usage of search -- note the example on that page 404s

  "search": {
        "search":          {string}  // Search term
        "regex":           {boolean} // Indicate if the search term should be treated as regex or not
        "smart":           {boolean} // Flag to enable DataTables smart search
        "caseInsensitive": {boolean} // Case insensitive flag
    },

My code attempts to shoehorn searchbuilder into the predefined item but obviously fails...

buttons:[
     extend: 'savedStatesCreate',
     config: {
          'saveState': {search: false},
          'creationModal': true,
          preDefined:{
              "Expires in 1 Year":{
                   searchBuilder: {
                        'criteria': [{
                            'condition': '<',
                            'data' "expiration date",
                            'origData: 'ExpirationDate',
                            'type': 'date',
                            'value': ['2023-02-18']
                        ], logic: 'and'}
                   }
               }
          }
     }
]

I have a feeling the only way is to somehow set "expires in 1 year" to .searchBuilder.rebuild(stuff) -- where stuff is everything in criteria from above. Am I on the right track here?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    It seems the predefined configuration item only allows usage of search -- note the example on that page 404s

    It should work, if you can link to a test case showing the 404 we can take a look. This example here, look at the Ajax tab at the end of the data, shows Scroller and ordering preDefined rules. That said, I just noticed that the scroll isn't working - I've raised it internally (DD-2472 for my reference) and we'll report back here when there's an update.

    I find the easiest way to work out the format for the state, is to create it, then display the state information with stateRestore.states() - you can see the expected format then,

    Colin

  • Hon3yNutzHon3yNutz Posts: 13Questions: 3Answers: 0

    Sorry for the delay in responding -- so the 404 is from this link in particular
    https://datatables.net/extensions/StateRestore/examples/initialisation/preDefined.html

    This link is accessed from the example in the description here: https://datatables.net/reference/option/stateRestore.preDefined

    As for getting stateRestore.state() to work i assume you mean through a console log? I will give it a shot and report back

  • Hon3yNutzHon3yNutz Posts: 13Questions: 3Answers: 0

    UGH Missed a '}' Everything works as indicated using this code. I highly recommend using this in tandem with https://datatables.net/extensions/searchbuilder/examples/api/rebuild.html

    where you will get an output like this

    {
        "criteria": [
            {
                "condition": "=",
                "data": "Position",
                "type": "string",
                "value": [
                    "Accountant"
                ]
            }
        ],
        "logic": "AND"
    }
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    That's a good tip, thanks for posting so others can see it too,

    Colin

Sign In or Register to comment.