gpt4 book ai didi

Jquery数据表过滤器

转载 作者:行者123 更新时间:2023-12-01 01:09:42 25 4
gpt4 key购买 nike

我有一个使用日历图像的数据表日期过滤器,效果很好。但是当我清除日期时,它不会显示所有日期。

如何制作一个按钮来显示所有日期,从而清除日期过滤器?

对此的任何帮助/建议都会很棒,提前谢谢您。

// The plugin function for adding a new filtering routine
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex){
var dateStart = parseDateValue($("#dateStart").val());
// aData represents the table structure as an array of columns, so the script access the date value
// in the first column of the table via aData[0]
var evalDate= parseDateValue(aData[3]);

if (evalDate == dateStart ) {
return true;
}
else {
return false;
}

});

// Function for converting a mm/dd/yyyy date value into a numeric string for comparison (example 08/12/2010 becomes 20100812
function parseDateValue(rawDate) {
var dateArray= rawDate.split("/");
var parsedDate= dateArray[1] + dateArray[0] + dateArray[3];
return parsedDate;
}



$(function() {
// Implements the dataTables plugin on the HTML table
var $oTable= $("#example").dataTable( {
"iDisplayLength": 20,
"oLanguage": {
"sLengthMenu": 'Show <select><option value="25">25</option><option value="50">50</option><option value="100">100</option><option value="200">200</option></select>'
},
"bJQueryUI": true,
"aoColumns": [
null,
null,
null,
{ "sType": "date" }
]
});


// The dataTables plugin creates the filtering and pagination controls for the table dynamically, so these
// lines will clone the date range controls currently hidden in the baseDateControl div and append them to
// the feedbackTable_filter block created by dataTables
$dateControls= $("#baseDateControl").children("div").clone();
$("#feedbackTable_filter").prepend($dateControls);

// Implements the jQuery UI Datepicker widget on the date controls
$('.datepicker').datepicker(
{dateFormat: 'DD, d MM, yy', showOn: 'button', buttonImage: '../images/calendar.jpg', buttonImageOnly: true}
);

// Create event listeners that will filter the table whenever the user types in either date range box or
// changes the value of either box using the Datepicker pop-up calendar
$("#dateStart").keyup ( function() { $oTable.fnDraw(); } );
$("#dateStart").change( function() { $oTable.fnDraw(); } );

});

最佳答案

那么,你尝试过吗:

$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex){
var dateStart = parseDateValue($("#dateStart").val());
//if filter is empty return everything
if(dateStart === ''){
return true;
}
// aData represents the table structure as an array of columns, so the script access the date value
// in the first column of the table via aData[0]
var evalDate= parseDateValue(aData[3]);

if (evalDate == dateStart ) {
return true;
}
else {
return false;
}

});

如果这不起作用,你可以在 jsfiddle 上发布一个示例吗?

编辑 - 好吧,问题出在 parseDateValue() 上,它期望使用 / 创建日期。由于您想要精确匹配,因此可以省略 parseDateValue()

// The plugin function for adding a new filtering routine
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex){
var dateStart = $("#dateStart").val();
//if filter is empty return everything
if(dateStart === ''){
return true;
}
// aData represents the table structure as an array of columns, so the script access the date value
// in the first column of the table via aData[0]
var evalDate= aData[3];

if (evalDate == dateStart ) {
return true;
}
else {
return false;
}

});

在这里摆弄http://jsfiddle.net/eMZtV/1/

关于Jquery数据表过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9719341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com