Retrieving only the rows for a selected day

Retrieving only the rows for a selected day

ChrisKolliChrisKolli Posts: 28Questions: 8Answers: 0

Hey guys so i have a big table in my database that i only want todays rows to be retrieved.
I got a datepicker working and the selection works too, but only if I reload the page,

Basically i dont know how to reload the table after selecting a date.

This is my ajax call that works when i reload the page:

        var table = $('#calendar').DataTable( {
            dom: 'Brtf',
            ajax: {
                url: 'php/table.calendar.php',
                type: 'POST',
                data: {
                    'Date' : $('#submittedDate').val(),
                }
            },  
            columnDefs:[
                {...},
            ],
            order: [],
            columns: [
                {...}

The "where" condition in my php:

->where( 'date', $_REQUEST['Date'])

and the js of the datepicker:

$(document).ready(function() {

            $(".datepicker").datepicker({
                altField  : '#submittedDate',
                altFormat : 'yy-mm-dd',
                dateFormat : 'dd.mm.yy',
                showOn: "button",
                showAnim: 'slideDown',
                showButtonPanel: true ,
                autoSize: true,
                buttonImage: "//jqueryui.com/resources/demos/datepicker/images/calendar.gif",
                buttonImageOnly: true,
                buttonText: "Select date",
                closeText: "Clear"
            });
            $('#displayedDate').on('click', function () {
                $('#calendar').DataTable().ajax.reload();
            });
        });

So what do i hve to do to reload the table?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 13,780Questions: 25Answers: 3,242

    Try using ajax.data as a function otherwise it will only use the value of $('#submittedDate').val() found at initialization.

    Kevin

  • ChrisKolliChrisKolli Posts: 28Questions: 8Answers: 0

    I'm a bit confused, what do you mean?

    like this?

    ajax: {
            url: 'php/table.calendar.php',
            type: 'POST',
            data:function ( d ) {
             'Date' : $('#submittedDate').val(),
             table.ajax.reload();
            }
        },  
    
  • kthorngrenkthorngren Posts: 13,780Questions: 25Answers: 3,242
    Answer ✓

    Take a look at the ajax.data examples. Do something like this:

    ajax: {
            url: 'php/table.calendar.php',
            type: 'POST',
            data:function ( d ) {
               d.Date = $('#submittedDate').val()
            }
        }, 
    

    Kevin

  • ChrisKolliChrisKolli Posts: 28Questions: 8Answers: 0

    got it to work :smiley:

    used your code and fixed mine I had a mistake in my reload function. works like this now

Sign In or Register to comment.