Set page in URL?

Set page in URL?

versakversak Posts: 26Questions: 0Answers: 0
edited October 2012 in General
I've got filters and sorting being saved to and extracted from a URL so users can link directly to sorted and/or filtered tables, but the one think I have yet to solve is getting the pagination page into the url. Using cookies has not seemed to work for individual users but my ultimate goal would be to have it in the URL. Currently all the states are being saved to the URL via inputs holding values for the filters and sorting all within a form. I have jquery add the values to the URL on particular events, but i can't seem to make it work with the pagination anchors.

Is there any way to do this? I cannot post code because it's all on a local intranet. I'm using fairly basic DataTables stuff with no backend processing.

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    You can use the iDisplayStart initialisation parameter. You'd line a line or two of Javascript to get the parameter you want from the URI, but then when you've got it, just pass it into DataTables.

    Allan
  • srayner02srayner02 Posts: 15Questions: 0Answers: 0
    This sounds what i would like to do, have url parameter to indicate the current page, but how do i get the parameter into the url in the first place?

    Is it possible to update the url after each ajax request to reflect the current page, without full page reload, which would defeat the point of ajax?
  • versakversak Posts: 26Questions: 0Answers: 0
    I decided to put it in a cookie and it might be overcomplicated but here's what I did (excuse any typos, i'm copying from an intranet):

    [code]
    **my table id is "openTable"

    var displayLength = $.cookie("cookieName_dLen") == null ? 20 : $.cookie("cookieName_dLen") ;
    var displayStart = $.cookie("cookieName_dStart") == null ? 0 : $.cookie("cookieName_dStart") ;

    $("#openTable").ready(function(){
    $("openTable").dataTable({
    "iDisplayLength": displayLength,
    "iDisplayStart": displayStart
    ....etc.....
    });

    $("paginate_button").live("click", function(event) {
    var theLen = $("select[name='openTable_length']").val();
    var thePage = ($(this).text()*1-1) * theLen;
    $.cookie("cookieName_dStart", thePage, {expires:90});
    return false;
    });
    $("select[name='openTable_length']").change(function(){
    $.cookie("cookieName_dLen", $("select[name='openTable_length']").valu(), {expires:90});
    });
    [/code]
This discussion has been closed.