Save datepicker range

Save datepicker range

m75sam75sa Posts: 132Questions: 30Answers: 0
edited March 2022 in DataTables

Hi, i'm using datatable with date range filter by using datepicker.
When i set
stateSave: true

it saves all values except the range set into the input datepicker field.
Any help on this?

Have a look here:
http://live.datatables.net/kajabeli/2/edit

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thanks for the link. I don't see anything there that is saving the date values into the state storage or that is writing them back when the state is loaded.

    You've used stateSaveParams and stateLoadParams which is correct, but your functions need to integrate with your custom date inputs as well.

    Allan

  • m75sam75sa Posts: 132Questions: 30Answers: 0

    thanks allan, can you help me how to integrate?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Writing a custom example is something that would fall under our pro support packages.

    However, writing a value to the state is something just like: data.start_date = $('#start_date').val();. Restoring it is similar.

    Allan

  • m75sam75sa Posts: 132Questions: 30Answers: 0

    thanks Allan, unfortunally i cannot manage it... for this reason I wrote on this forum in order to "learn" from a workly example. But i f this is related to a payment plan subscription I don't want to insist. :(

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    I updated your example with what Allan suggested:
    http://live.datatables.net/kajabeli/12/edit

    I assume the button below is used for searching the date range and that you have a function for this. I created a click event for the button which executes draw(). This saves the state.

    Kevin

  • m75sam75sa Posts: 132Questions: 30Answers: 0

    Thanks a lot @kthorngren, now i can learn from your example! Very appreciated

  • m75sam75sa Posts: 132Questions: 30Answers: 0
    edited March 2022

    @kthorngren sorry, thanks to your example now i'm able to save the date picker value also if i reload the page... but i would like to pass via ajax the saved values to the post.
    So in addition to your code, i have:

    ajax : {
    url:"file.php",
    type:"POST",
    data:{
    start_date:start_date, end_date:end_date
    }
    }

    where start_date and end_date are setted by this block:

    $('#search').click(function(){
    var start_date = $('#start_date').val();
    var end_date = $('#end_date').val();
    });

    What i'm not able to do is to pass the saved date-picker to the post in order to have the correspondent result when the user reload the page...

    hope you understood what i mean and thanks again !

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited March 2022 Answer ✓

    Assuming you are using ajax you would use ajax.data as a function. See the examples in the docs. Also see this running example.

    Kevin

  • m75sam75sa Posts: 132Questions: 30Answers: 0

    thanks @kthorngren, all clear now! :smile:

  • m75sam75sa Posts: 132Questions: 30Answers: 0
    edited April 2022

    @kthorngren again me...
    now happens that the datepicker input has, as default value, the state save. And this is correct. But if i want that every time I open the page the default status of the date-picker value is the current date (and not the save state)? So only the first time... then when i change the date-picker value of course the save.state should work...

    I set on the input value the code like:

    <input name="start_date" type="date" class="form-control" id="start_date" value="<? echo date("Y-m-d") ?>" />

    so when i open the page, and there is no state.save, i can see the current date... correct, but when i click the picker date the state.save starts working so the next time I will re-open the page I will NOT see the current date anymore...
    Any ideas how to set the behaviour?
    thanks a lot

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.