How to parse stateSave values

How to parse stateSave values

lenamtllenamtl Posts: 265Questions: 65Answers: 1

I'm using Datatables on a multi-language application.

I want to notify the user that a search value is set in** stateSave values**.

So how could I parse stateSave values to find out if all "search":""are empty?

{"time":1520535457114,"start":0,"length":10,"order":[[2,"asc"],[0,"asc"],[1,"asc"]],"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true},"columns":[{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}}],"ColReorder":[0,1,2,3],"naruto":"kurama"}

**Note: I'm looking for a way to parse the info, I'm not looking for a way to get the info from search fields.
Thanks

This question has an accepted answers - jump to answer

Answers

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited March 2018

    Using this example

    http://live.datatables.net/banomuqi/1/edit

    the search values appear in console.log for each column and main table search
    but how can I check if all are empty?

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

    Hi lenamtl,

    That's just JS object/array parsing - take a look at this modified example, now it'll display a message if no searches are active on table initialisation.

    Cheers,

    Colin

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited March 2018

    Could you check there is an error.

    Also how could I get the same on page load?

    Thanks for your time I appreciate

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

    I'm not seeing an error - are you sure?

    And for page load, you can just add another event listener, like the one at the of the code.

    C

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    Error in console is:
    Uncaught TypeError: Cannot read property 'columns' of null

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

    ah, that will be if you have saveState disabled, or possibly on the first execution - it just needs a check to make sure that the retrieved state isn't null.
    C

This discussion has been closed.