[英]yadcf initial filter value when page loads
So I have been looking around for an answer on how to do this and haven't had much luck so I thought I would post something on here. 因此,我一直在寻找有关如何执行此操作的答案,但运气不太好,因此我想在此发布一些内容。 What I'm looking for is a way to set a default value for a filter so when the page loads it will automatically search the datatable according to this initial value.
我正在寻找的是一种为过滤器设置默认值的方法,因此当页面加载时,它将根据该初始值自动搜索数据表。 For example.
例如。 I would like to pre-load the range_date filter with a specific date - A date that will actually be taken from a $_GET variable, so this value can not be hard coded.
我想预加载带有特定日期的range_date过滤器-该日期实际上将从$ _GET变量中获取,因此无法对该值进行硬编码。 My current column code looks like this....
我当前的列代码如下所示。
{column_number : 4, filter_type: "range_date", date_format: 'yy-mm-dd'},`enter code here`
So far I have found one source about adding exFilterColumn
but there are no examples on how to get this working with filter_type: "range_date"
Any ideas? 到目前为止,我已经找到一个有关添加
exFilterColumn
但是没有关于如何filter_type: "range_date"
与filter_type: "range_date"
一起使用的示例filter_type: "range_date"
什么想法吗?
After a bit of digging I have figured out how to get exFilterColumn
working with a range_date filter. 经过一番挖掘,我想出了如何使
exFilterColumn
与range_date过滤器一起使用。 First I had to add the following to my column initialization: 首先,我必须在列初始化中添加以下内容:
filter_delay: 1500, filter_default_label: 'Search'
Then I had to add 然后我必须添加
yadcf.exFilterColumn(tableOne, [
[1, {
from: '2016-11-02',
to: '2016-11-03'
}],
]);
My complete code looks like this: 我完整的代码如下:
// Appointment datatable
var table = $('#tableID').dataTable( {
"processing": true,
"serverSide": true,
"ajax":{
url :"ajax/users-get-table-data.php" // json datasource
type: "post", // method , by default get
data:"workOrderStatusID=2",
},
}).yadcf([
{column_number : 0, filter_type: "text", filter_default_label: ['Search']},
{column_number : 1, filter_type: "range_date", date_format: 'yy-mm-dd', filter_delay: 1500, filter_default_label: 'Search'}
]);
yadcf.exFilterColumn(table, [
// 1 is the matching column of my targeted range_date filter
[1, {
<? //setting the date from get variable
$date = mysqli_real_escape_string($mysqli,$_GET['date']);
$tomorrow = date('Y-m-d',strtotime($date . "+1 days"));
?>
from: '<? echo $date; ?>',
to: '<? echo $tomorrow; ?>'
}],
]);
Incase you are reading this and want to pre load a regular column filter (not a range date) you can use the following: 如果您正在阅读此书并想要预加载常规列过滤器(而不是范围日期),则可以使用以下方法:
yadcf.exFilterColumn(table, [
// 1 being the column number, and "value" being the value you want it to initially search for when page loads
[1, "value"]
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.