Looking for API for the filter value

Looking for API for the filter value

duselguyduselguy Posts: 24Questions: 3Answers: 0

Hello,
For now I see only this way:
In search event handler to get settings.oPreviousSearch.sSearch .
But it is not recommended to use settings for read/write.
Any ideas?
Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    You want to get the column filter value? Use column().search().

    Allan

  • duselguyduselguy Posts: 24Questions: 3Answers: 0
    edited January 2016

    No. The filter value from the search box to provide my own search.
    My conf is:

            var table = $('#example').DataTable({
                serverSide:     true,
                scrollX:        true,
                scrollY:        0,
                scrollCollapse: false,
                scroller:       {
                    serverWait: 0
                },
                paging:         true,
                info:           true,
                ordering:       false,
                searching:      true,
                search:         {
                    smart: false
                },
                ajax:           function (data, callback, settings){
    ...
                        }
                    }
                    callback({
    ...
                },
                rowCallback:    function (row, data) {
    ...
                    }
                }
            });
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    You are using serverside, the search filter is passed in the URL / page request with each ajax call. Can you just pull it from there in your ajax page? Otherwise, you can look at the input value for the search boxes id which is {yourtableid}_filter.

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Use search() if you want to get the global search value on the client-side.

    Allan

  • duselguyduselguy Posts: 24Questions: 3Answers: 0
    edited January 2016

    Hello,
    Thank you for the comments.
    I have no server - all data are processed locally. I'm using server-side and Scroller to process large tables (> 1000000 rows) with my own load, sort and search. For now, I'm using search event to provide my own search (although this event is schedulled too often :-). Using of my own handler for search box looks not good for me because DataTables already has good staff to process it. search() API is not suitable in my case. Should think about possibility to get/parse url to get the filter (instead of the search event processing). P.S. Really, my question was common: if settings should not be used directly, why there is no API to get settings' values to hide realization details and to protect from DT version to version changes. P.S.S. Thanks a lot for the great product and support.

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    I have no server - all data are processed locally

    But you have the serverSide option enabled in your above configuration. If you don't have server-side processing available, I'm not sure why that is enabled?

    Really, my question was common: if settings should not be used directly, why there is no API to get settings' values to hide realization details and to protect from DT version to version changes.

    A lot of the information needed externally is available via the API - for example the search() will given the current search term. There are other properties such as the sortable and filterable options which are no available via the API (although I plan to add them), but the majority of the internal properties are not useful externally and / or DataTables cannot cope with them being updated externally.

    Allan

  • duselguyduselguy Posts: 24Questions: 3Answers: 0
    edited January 2016
    1. serverSide:
      I used http://datatables.net/extensions/scroller/examples/initialisation/server-side_processing.html as a sample.

    2. Filter value:
      I don't know how var x = settings.oPreviousSearch.sSearch in search event handler may be replaced by var x = table.search(input, ...) somewhere.

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin
    Answer ✓

    Just use var x = table.search() to get the current search term.

    Allan

  • duselguyduselguy Posts: 24Questions: 3Answers: 0
    edited January 2016

    Thank you,
    I missed this, because search is in 2 forms in the reference. And I looked into the second :-(

This discussion has been closed.