我在yii1上使用数据表。我在视图文件中有以下代码:
<div class="form-group col-xs-12 col-md-4">
<label class="col-sm-6 control-label" for="formGroupInputSmall">Member From</label>
<div class="col-sm-6">
<input type='date' class="form-control" value='' id='fini' data-column-index='8'>
</div>
</div>
<div class="form-group col-xs-12 col-md-4">
<label class="col-sm-6 control-label" for="formGroupInputSmall">Member to</label>
<div class="col-sm-6">
<input type='date' class="form-control" value='' id='ffin' data-column-index='9'>
</div>
</div>
在js文件中,我有以下代码:
$(document).ready(function() {
var table = $('#table_id').DataTable();
/* Add event listeners to the two range filtering inputs */
$('#fini').keyup( function() { table.draw(); } );
$('#ffin').keyup( function() { table.draw(); } );
} );
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iFini = document.getElementById('fini').value;
var iFfin = document.getElementById('ffin').value;
var iStartDateCol = 8;
var iEndDateCol = 9;
iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2);
iFfin=iFfin.substring(6,10) + iFfin.substring(3,5)+ iFfin.substring(0,2);
var datofini=aData[iStartDateCol].substring(6,10) + aData[iStartDateCol].substring(3,5)+ aData[iStartDateCol].substring(0,2);
var datoffin=aData[iEndDateCol].substring(6,10) + aData[iEndDateCol].substring(3,5)+ aData[iEndDateCol].substring(0,2);
if ( iFini === "" && iFfin === "" )
{
return true;
}
else if ( iFini <= datofini && iFfin === "")
{
return true;
}
else if ( iFfin >= datoffin && iFini === "")
{
return true;
}
else if (iFini <= datofini && iFfin >= datoffin)
{
return true;
}
return false;
}
);
当我输入日期时,datatable不返回任何结果。如果我将<input/>
的类型更改为文本,它将搜索确切的日期(不是特定的日期范围)。