How can I prepare a timeframe for searching

How can I prepare a timeframe for searching

mamadsolimamadsoli Posts: 15Questions: 3Answers: 0

hi
I want to have two date fields for searching...

example :

instead of this

createDate: <input type="date" name="createDate" />

I write

createDate: 
<input type="date" name="createDateFrom" placeholder="Create Date From" />
<input type="date" name="createDateTo" placeholder="Create Date From" />

This question has an accepted answers - jump to answer

Answers

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

    This example shows how to do with an age, so you could use that as a template.

    Colin

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0
    edited October 2019

    Hi @colin
    Thanks, i need server Side example .

    how to send data for server

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

    Hi @mamadsoli ,

    You would add it into the ajax.data, then it gets sent to the server,

    Cheers,

    Colin

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0

    excuse me but i don`t know.
    Should not set data in column and search In the form below:

    table.column(index).search(the_word).ajax.reload();
    

    Can You Explain more :no_mouth:

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0

    i can not find example

    i write a code is here:
    http://live.datatables.net/qadoxalu/8/edit

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    To send the extra parameters needed for the two dates you would use ajax.data as mentioned by Colin. The second example in the docs show how to add the extra search data. Your server script will then need to get these parameters and use it as part of your search query. That part is specific to what you are using for your server script.

    Kevin

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0
    edited October 2019

    hi @kthorngren

    thankyou for your answer
    you confused me the most. your example Very strange.

    I just want to search for a field that is not in the list of columns.
    This process should be done with the search button.

    i want a example please

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

    Sorry that was the wrong link, try this - look at the second example:
    https://datatables.net/reference/option/ajax.data#Examples

    I updated you example to show this:
    http://live.datatables.net/qadoxalu/9/edit

    I changed your ajax to use ajax.data like this:

        "ajax": {
          "url": "http://live.datatables.net/ssp/server_processing.php",
          "data": function ( d ) {
              d.age_min_search = $('#min').val();
              d.age_max_search = $('#max').val();
          }
        }    
    

    I also simply use table.draw(); to perform the search.

    Use the browser's developer tools to see the Ajax request sent to the server. This technote will provide the steps if you need.

    If you are using chrome scroll to the bottom of the Headers tab in the Network tools then click the Run JS button. You will see the added parameters age_min_search and age_max_search.

    start: 0
    length: 10
    search[value]: 
    search[regex]: false
    age_min_search: 
    age_max_search: 
    

    Now enter some data, for my example I entered 33 and 66 as shown in the screenshot:

    Look at the next XHR request in the Developer Tools and you will see the filled in values being sent to the server.

    start: 0
    length: 10
    search[value]: 
    search[regex]: false
    age_min_search: 33
    age_max_search: 66
    

    This is where your server script will need to get those parameters and use them as part of your query search to fetch the desired rows.

    HTH,
    Kevin

  • mamadsolimamadsoli Posts: 15Questions: 3Answers: 0

    @kthorngren
    Thanks, i Know .
    It was great and I totally understood.
    And after pressing the f12 key, I saw that the information was being correctly transferred to the server.
    And your explanation was clear to me.

    I was also pleased with @colin answer.But I couldn't understand.

    thank you very match

This discussion has been closed.