2016-11-01 64 views
0

我有一個代碼來過濾dataTables到日期。問題是,代碼工作正常,但只有當Y型與鍵盤的日期,而不是挑喜歡的圖像日期:jQuery Datepicker onClose

datePicker problem

如何can'i設置datapicker的OnClose選項:

$(document).ready(function(){ 
     $('#data .input-daterange').datepicker({ 
      todayBtn: "linked", 
      keyboardNavigation: false, 
      forceParse: false, 
      autoclose: true, 
      format: "dd-mm-yyyy", 
      onClose: ???????????????? 
      }, 
     }); 

     /* Add event listeners to the two range filtering inputs */ 
     $('#min, #max').keyup(function() { oTable.draw(); }); 
    }); 

使在這個代碼配置的dataTables工作過濾器?

/* Function for date filter */ 
    jQuery.fn.dataTableExt.afnFiltering.push(
     function(oSettings, aData, iDataIndex) { 
      var iMin = document.getElementById('min').value; 
      var iMax = document.getElementById('max').value; 

      var iMinimo_year = iMin.substring(6,10); 
      var iMinimo_month = iMin.substring(3,5); 
      var iMinimo_day = iMin.substring(0,2); 
      var iMinimo = iMinimo_year.concat(iMinimo_month,iMinimo_day); 

      var iMaximo_year = iMax.substring(6,10); 
      var iMaximo_month = iMax.substring(3,5); 
      var iMaximo_day = iMax.substring(0,2); 
      var iMaximo = iMaximo_year.concat(iMaximo_month,iMaximo_day); 

      var iCol = 5; 
      var iDate_year = aData[iCol].substring(6,10); 
      var iDate_month = aData[iCol].substring(3,5); 
      var iDate_day = aData[iCol].substring(0,2); 
      var iDate = iDate_year.concat(iDate_month,iDate_day); 

      if ((iMinimo === "" && iMaximo === "") || (iMinimo <= iDate && iMaximo === "") || (iMinimo === "" && iMaximo >= iDate) || (iMinimo <= iDate && iMaximo >= iDate)) { 
       return true; 
      } else { 
       return false; 
      } 
     } 
    ); 

的HTML部分是:

  `<div class="form-group col-md-offset-4" id="data"> 
       <label class="font-noraml">Seleccione rango de fechas de ingreso de solicitud a filtrar</label> 
       <div class="input-daterange input-group" id="datepicker"> 
        <input type="text" class="input-sm form-control" name="min" id="min" value="<?php echo date('');?>"/> 
        <span class="input-group-addon">a</span> 
        <input type="text" class="input-sm form-control" name="max" id="max" value="<?php echo date('d-m-Y');?>" /> 
       </div> 
      </div> 

`

+0

你可以在這裏粘貼代碼,當您手動鍵入日期執行? – void

+0

是否上面的代碼,onClose行除外: – rjgodoy

回答

0

我認爲你正在尋找onSelect

堪稱是選擇的日期選擇器時。該函數將所選日期作爲文本並將日期選擇器實例作爲參數。這指的是相關的輸入字段。

像這樣的事情

$(document).ready(function(){ 
    $('#data .input-daterange').datepicker({ 
     todayBtn: "linked", 
     keyboardNavigation: false, 
     forceParse: false, 
     autoclose: true, 
     format: "dd-mm-yyyy", 
     onSelect: function(dateVal) { 
      alert(dateVal); //Method to call when user picks a date 
     }, 
     onClose: function(dateVal) { 
      alert(dateVal); //Method to call when user closes the date picker 
     }, 
    }); 
}); 
+0

謝謝,但我怎樣才能配置該選項? – rjgodoy