[英]how can i set a default value for date in jQuery filter
I am using a JQuery to show a table out of a database which I am filtering with the datetimepicker
. 我正在使用JQuery显示数据库中的表,该数据库正在使用
datetimepicker
过滤。
What I am trying is to set a default value for my filter as the current day. 我正在尝试将过滤器的默认值设置为当天。
So as default it should only show me data from the current day. 因此,默认情况下,它仅应显示我当天的数据。
I already tried a lot and searched for many questions here, but it didn't really help me. 我已经尝试了很多,并在这里搜索了许多问题,但这并没有真正帮助我。
I tried to set it with JS as defaultDate and tried to set it after initialization with a variable. 我尝试使用JS将其设置为defaultDate,并尝试在初始化后使用变量进行设置。
At the moment it loads all the data out of the database, which takes a bit, so I want to change it to this way. 目前它将所有数据从数据库中加载出来,这需要一点时间,因此我想将其更改为这种方式。
HTML HTML
<div class='input-group date' id='datepicker1' style="width: 220px;">
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
nach Datum
</span>
<input type='text' id="filterdatum" name="datum" value="{FILTERDATUMDEUTSCH}" class="form-control" />
</div>
JS JS
$(document).ready(function() {
$('#datetimepickerzeit').datetimepicker({
locale: 'de',
format: 'DD.MM.YYYY HH:mm:ss'
});
// Datum filtern
$('#datepicker1').datetimepicker({
locale: 'de',
format: 'D.M.YYYY'
});
$('#datepicker1').on('dp.show', function () {
$('#datepicker1').on('dp.change', function () {
window.location = "?module=ausschuss&action=showtable&filterdate=" + $('#datepicker1').data("DateTimePicker").date().format('YYYY-MM-DD');
});
});
Two things I'd try. 我会尝试两件事。 First, make sure you have a link to jQuery above your script block.
首先,请确保您在脚本块上方具有指向jQuery的链接。 Use either Google's or a local copy:
使用Google的副本或本地副本:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
If that doesn't work, next try replacing all instances of $ in your Javascript code with jQuery: 如果那不起作用,接下来尝试用jQuery替换Java代码中$的所有实例:
jQuery(function(){
jQuery('#id1').daterangepicker({
defaultDate: new Date(),
arrows:true,
onChange: function(){
jQuery('#frmDate').submit()
},
});
});
you can also try defaultDate: new Date(), in your code. 您还可以在代码中尝试defaultDate:new Date()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.