Sticky Pagination?

Sticky Pagination?

thekruserthekruser Posts: 3Questions: 0Answers: 0
edited December 2012 in General
First, thank you for this AMAZING app. I cannot tell you how much time it has saved me...let alone server load! Fantastic!

I know next to nothing of .js. I am more of a .php guy. Within my DataTable, I have links. When a user exits the page and returns, they have to re-enter their search criteria into DataTables to return to where they were. Right now, I am getting around it using target="_blank" but would like to avoid this if possible. Is there some sort of cookie functionality that I am missing? If not, is there a way to do this?

The site I am working on is in beta at the moment and is available through invite only. Should you like to see it, it is at http://foursquareguru.com/foursquare-badge-list/. You will have to use code: DATATABLES.

Thanks for your time and help! Have a great day!

-thekruser

Replies

  • radi8radi8 Posts: 31Questions: 6Answers: 0
    Set the search criteria into a $_SESSION variable. When the user returns to the page, load the value into a hidden element and then set the value using JS. This would be my first guess and option.
  • thekruserthekruser Posts: 3Questions: 0Answers: 0
    @radi8-

    Thank you for your reply! I can do the $_SESSION part, but have no idea how to go about loading the vars by JS. Any insight would be greatly appreciated.
  • radi8radi8 Posts: 31Questions: 6Answers: 0
    edited December 2012
    I just checked and DataTables does not assign an ID or name to the search field. There may be a way to get the value into the search field after dataTables has been initialized, but will have to inspect the DOM more.

    I did find the following:
    [url]http://datatables.net/ref#oSearch[/url]
    and also
    [url]http://stackoverflow.com/questions/11006402/initialize-search-input-in-jquery-datatables[/url]

    So it looks like you could use some jQuery like this:

    [code]

    $(document).ready( function() {
    var val = $('#hiddendata').val();
    // check for empty string
    if(val.length > 0){
    $('#example').dataTable( {
    "oSearch": {"sSearch": val}
    } );
    }
    else{
    $('#example').dataTable();
    }
    });

    // or maybe even something like this:
    $(document).ready( function() {
    $('#example').dataTable( {
    "oSearch": {"sSearch": $('#hiddendata').val()}
    })
    });
    [/code]

    or soemthing similar.
  • thekruserthekruser Posts: 3Questions: 0Answers: 0
    @radi8-

    Thank you for taking the time to help me out. I will try incorporating this fix. You rock!!
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    To set the filter after initialisation you can use fnFilter - `table.fnFilter( $('#hiddendata').val() );` for example and that will appear in the global filter input by default (that can be disabled if needed).

    Allan
This discussion has been closed.