alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.77k stars 363 forks source link

Query resets date input #243

Open mcgrottys opened 8 years ago

mcgrottys commented 8 years ago

I've just gotten into using Dynatable and have recently made my own date range picker which works well for the most part. But there is one problem each time I load the page the first time I chose a date it resets the other date Input. I've tried changing the value back within the query but that doesn't work. It's not a big deal but it's a nuisance. Here is my code so you can get an idea of my situation. I might just be missing a step.

//On Ready

           $('#my-table').bind('dynatable:init', function (e, dynatable) {
                dynatable.queries.functions['max-date'] = function (record, queryValue) {
                    endDate = $('#max-date').val();
                    if ((Date.parse(endDate) >= Date.parse(record.Date)) && (Date.parse(startDate) <= Date.parse(record.Date))) {
                        return true;
                    }
                    else {
                        return false;
                    }
                    //return parseFloat(record.price.replace(/,/, '')) <= parseFloat(queryValue);
                },
                dynatable.queries.functions['min-date'] = function (record, queryValue) {
                    startDate = $('#min-date').val();
                    if ((Date.parse(endDate) >= Date.parse(record.Date)) && (Date.parse(startDate) <= Date.parse(record.Date)))
                        return true;
                    else
                        return false;
                    //return parseFloat(record.price.replace(/,/, '')) <= parseFloat(queryValue);
                };
            }).dynatable({
                dataset: {
                    records: items,
                    perPageDefault: 20,
                    perPageOptions: [10, 20, 50, 100]
                },
                table: {
                    defaultColumnIdStyle: 'trimDash'
                },
                features:
            {
                pushState: false
            },
                inputs: {
                    queries: $('#max-date,#min-date')
                }
            });
                 $('#my-table').bind('dynatable:init', function (e, dynatable) {
                dynatable.queries.functions['max-date'] = function (record, queryValue) {
                    endDate = $('#max-date').val();
                    if ((Date.parse(endDate) >= Date.parse(record.Date)) && (Date.parse(startDate) <= Date.parse(record.Date))) {
                        return true;
                    }
                    else {
                        return false;
                    }
                    //return parseFloat(record.price.replace(/,/, '')) <= parseFloat(queryValue);
                },
                dynatable.queries.functions['min-date'] = function (record, queryValue) {
                    startDate = $('#min-date').val();
                    if ((Date.parse(endDate) >= Date.parse(record.Date)) && (Date.parse(startDate) <= Date.parse(record.Date)))
                        return true;
                    else
                        return false;
                    //return parseFloat(record.price.replace(/,/, '')) <= parseFloat(queryValue);
                };
            }).dynatable({
                dataset: {
                    records: items,
                    perPageDefault: 20,
                    perPageOptions: [10, 20, 50, 100]
                },
                table: {
                    defaultColumnIdStyle: 'trimDash'
                },
                features:
            {
                pushState: false
            },
                inputs: {
                    queries: $('#max-date,#min-date')
                }
            });
            startDate = "2016-04-01";
            endDate = new Date().toDateInputValue();
            $('#min-date').val("2016-04-01");
            $('#max-date').val(new Date().toDateInputValue());  
 <input id="min-date" type="date" data-dynatable-query="min-date" >
<input id="max-date" type="date" data-dynatable-query="max-date" >     
        <table id="my-table" style="width: 100%; color: #006464">
            <thead>
                <th>Date</th>
                <th>Initiator</th>
                <th>IssueType</th>
                <th>Action</th>
                <th>Operators</th>
            </thead>
            <tbody>
            </tbody>
        </table>