How to get the current value of an option?

How to get the current value of an option?

pmorchpmorch Posts: 6Questions: 1Answers: 0
edited May 2017 in Free community support

Hi,

I understand how to set an option at initialization. I understand that one can call .init() on the API to get back the options that were set at initialization. E.g.

var esTable = jQuery('#eventSources').show().dataTable({
    language: {
        searchPlaceholder: "Search my stuff",
    },
    scrollY: "200px",
    "searching": false,
    columns: myColumns,
});

From somewhere else, I now can query "searching" by api.init().searching, but only if it was set during init, otherwise the default value is true and api.init().searching is undefined.

Is there some way for me to ask for the current value of searching, regardless of how it was set?

The old-school deprecated jQuery object still allows me to e.g. $('#table').dataTable().fnSettings().sDom.match(/i/) - how do I do that today using the new API?

settings() looks promising, but confusingly it returns an API instance and I already have an API instance.api.settings().settings().settings().settings().settings() is valid, but for some reason api.settings() == api.settings().settings() is false. The settings() API makes no sense to me.

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    if all you want is the value , get it directly
    this code is running at http://jsbin.com/xiqiwuj/edit?html,css,js,output

              $("#example_filter").on("keyup","input" ,function(){
                    
                    window.sessionStorage.setItem("example_filter", this.value)
                })
                
                $("#btnSearchValue").click(function(){
                    alert(window.sessionStorage.getItem("example_filter"));
                });
    
    
  • pmorchpmorch Posts: 6Questions: 1Answers: 0

    @bindrid : That gets the current search filter. A much easier way to do that is with api.search() which also gets the value of the current search filter.

    What I'm looking for is to be able to query the value of options generally.

    My example was the search option - whether searching is enabled at all. (And not the value of the current search filter)

    And I'm not actually specifically looking to see whether searching is enabled, but a general way to query the value of any option generically.

  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin
    Answer ✓

    settings() returned an API instance as an API instance can reference multiple DataTables - so you would need to do:

    table.settings()[0].sDom
    

    etc.

    Please note that using the internal settings object is not recommended! The parameters inside it can, do and will change between versions.

    If you must access it, make sure you wrap any access via a plug-in API method so you at least only have one place to update the code should they change.

    Having said that, yes you are correct, currently there is no public API to access the state of the various features. That would make a good generic plug-in API method on the download page...

    Allan

This discussion has been closed.