2017-07-19 44 views
1

我在.jqGrid中使用.timepickerfilterToolbar。我想添加一個圖像旁邊的過濾器欄,用戶應該看到他們點擊圖像時的時間。無法在日期選擇器中添加圖像

如果我只是使用$(element).timepicker();然後我看到我點擊過濾器欄的時間,但當我跟着時,timepicker根本不工作。

$(element).timepicker({ 
       showOn: "button", 
       buttonImage: "https://jqueryui.com/resources/demos/datepicker/images/calendar.gif", 
       buttonImageOnly: true, 
      }); 

相同的選項與datepicker一起使用。我在這裏錯過了什麼?這是由於jquery.timepicker.js版本?

工作演示

$(function() { 
 
    "use strict"; 
 

 
    $("#grid").jqGrid({ 
 
    colModel: [{ 
 
     name: "StartRunTime", 
 
     label: "Start Run Time", 
 
     align: "center", 
 
     sorttype: "time", 
 
     formatter: "time", 
 
     searchoptions: { 
 
     dataInit: function(element) { 
 
      $(element).timepicker(); 
 
     } 
 
     } 
 
    }], 
 
    data: [{ 
 
     StartRunTime: "12:00" 
 
    }], 
 
    
 
    caption: ".jqGrid Test" 
 
    }).jqGrid('filterToolbar', { 
 
    autoSearch: true 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/jquery.jqgrid.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/css/ui.jqgrid.min.css" rel="stylesheet" /> 
 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" rel="stylesheet" /> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.css"> 
 

 
<table id="grid"></table>

不工作演示

$(function() { 
 
    "use strict"; 
 

 
    $("#grid").jqGrid({ 
 
    colModel: [{ 
 
     name: "StartRunTime", 
 
     label: "Start Run Time", 
 
     align: "center", 
 
     sorttype: "time", 
 
     formatter: "time", 
 
     searchoptions: { 
 
     dataInit: function(element) { 
 
      $(element).timepicker({ 
 
      \t \t showOn: "button", 
 
      \t \t buttonImage: "https://jqueryui.com/resources/demos/datepicker/images/calendar.gif", 
 
      \t buttonImageOnly: true, 
 
      }); 
 
     } 
 
     } 
 
    }], 
 
    data: [{ 
 
     StartRunTime: "12:00" 
 
    }], 
 
    
 
    caption: ".jqGrid Test" 
 
    }).jqGrid('filterToolbar', { 
 
    autoSearch: true 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/jquery.jqgrid.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/css/ui.jqgrid.min.css" rel="stylesheet" /> 
 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" rel="stylesheet" /> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.css"> 
 

 
<table id="grid"></table>

回答

2

那不是有效的選擇,但你可以插入圖像和監聽這樣

$(document).on("click", ".showCalendar", function(){ 
    $("#gs_grid_StartRunTime").timepicker('show'); 
}); 
$('#gs_grid_StartRunTime').parent() 
    .after('<td><img class="showCalendar" src="https://jqueryui.com/resources/demos/datepicker/images/calendar.gif"></td>'); 

演示:

$(function() { 
 
    "use strict"; 
 

 
    $("#grid").jqGrid({ 
 
    colModel: [{ 
 
     name: "StartRunTime", 
 
     label: "Start Run Time", 
 
     align: "center", 
 
     sorttype: "time", 
 
     formatter: "time", 
 
     searchoptions: { 
 
     dataInit: function(element) { 
 
      $(element).timepicker(); 
 
     } 
 
     } 
 
    }, 
 
    { 
 
\t \t \t \t \t label: "Concept Name", 
 
\t \t \t \t \t name: "ConceptName", 
 
\t \t \t \t \t key: true, 
 
\t \t \t \t \t width: 100, 
 
\t \t \t \t \t align: "center" 
 
\t \t \t \t }], 
 
    data: [{ 
 
     StartRunTime: "12:00", 
 
     ConceptName: "ABC" 
 
    }], 
 

 
    caption: ".jqGrid Test" 
 
    }).jqGrid('filterToolbar', { 
 
    autoSearch: true 
 
    }); 
 
    $(document).on("click", ".showCalendar", function(){ 
 
    \t $("#gs_grid_StartRunTime").timepicker('show'); 
 
    }); 
 
    $('#gs_grid_StartRunTime').parent().after('<td><img class="showCalendar" src="https://jqueryui.com/resources/demos/datepicker/images/calendar.gif"></td>'); 
 
    
 
});
.showCalendar { 
 
\t margin: 0px 2px; 
 
\t cursor: pointer; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/jquery.jqgrid.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/css/ui.jqgrid.min.css" rel="stylesheet" /> 
 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" rel="stylesheet" /> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.9/jquery.timepicker.css"> 
 

 
<table id="grid"></table>

+0

這是有道理的,但它增加了一個形象,如果所有列我添加任何。這裏是鏈接,[jsfiddle](https://jsfiddle.net/gunjan_prmr/kkxa62wb/)。從給定的例子,我怎麼才能將它添加到'StartRunTime'列? – CSharper

+0

調用'.parent()。after()'更新了答案。 – ewwink

+0

這個工程。謝謝。 – CSharper

相關問題