![](/img/trans.png)
[英]Kendo-ui Grid: Can the standard HTML5 input date-time be used as a cell editor?
[英]how to set input focus on kendo-ui grid input inside bootstrap modal
在將我的kendo-ui網格移動到bootstrap模式中之前,我會點擊Add Row,然后選擇3個輸入中的第一個。 然后我會選擇第二個,然后是第三個然后選項卡到復選框按鈕,我將按下回車鍵並添加行。 然后焦點將返回到“添加行”按鈕,我可以按Enter鍵再次開始處理。 那么現在它在一個模態中我失去了除了標簽之外的一切。 我找到了使用jquery來應用焦點的解決方案,但我已經在我的網格控制器中有了它。
Kendo-ui網格控制器
$scope.mainGridOptions = {
dataSource: dataSource,
pageable: false,
toolbar: [{ name: "create", text: "Add Product", }],
columns: [
{ field: "product", title: "Product", width: "95px", editor: productEditor },
{
field: "price", title: "Price", width: "95px", format: "{0:c2}", editor: priceEditor
},
{
field: "sqft", title: "Square Feet", width: "95px", editor: sqftEditor
},
{
command: [{ name: 'edit', text: { edit: '', update: '', cancel: '' }, width: '20px' }, { name: 'destroy', text: '' }], title: ' ', width: '80px'
}],
editable: 'inline'
};
function productEditor(container, options) {
$('<input id="product" name="product" data-bind="value:product" data-productvalidation-msg="Put the Product!" />')
.appendTo(container)
.kendoMaskedTextBox({});
$("#product").focus(function () {
var input = $(this);
setTimeout(function () {
input.select();
});
});
};
function priceEditor(container, options) {
$('<input id="price" name="price" data-bind="value:price" data-step="10000" style="" data-productvalidation-msg="Put the Price!"/>')
.appendTo(container)
.kendoNumericTextBox({ format: 'c0', min: 0 });
$("#price").focus(function () {
var input = $(this);
setTimeout(function () {
input.select();
});
});
}
function sqftEditor(container, options) {
$('<input id="sqft" name="sqft" data-bind="value:sqft" data-step="500" style="" data-productvalidation-msg="Put the Sqft!"/>')
.appendTo(container)
.kendoNumericTextBox({ format: '0', min: 0 });
$("#sqft").focus(function () {
var input = $(this);
setTimeout(function () {
input.select();
});
});
};
語氣
<!-- Grid Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<div style="width:100%"><span class="modal-label">My Product Data</span><button style="float:right" class="btn btn-custom waves-effect" data-dismiss="modal"><i class="zmdi zmdi-close"></i></button></div>
</div>
<div class="modal-body">
<div kendo-grid id="grid" options="mainGridOptions"></div>
</div>
</div>
</div>
</div><!--End Grid Modal -->
打開模態的功能
$scope.openGrid = function () {
$('#myModal').modal('show');
};
在NumericTextBox Kendo-UI控件的API函數上,它顯示可以通過執行以下偽代碼獲得焦點:
var numerictextbox = $("#numerictextbox").data("kendoNumericTextBox");
numerictextbox.focus();
所以將它應用到您的代碼中它看起來像這樣:
var price= $("#price").data("kendoNumericTextBox");
price.focus();
此外,由於您的模態彈出窗口更像是一個應用程序,我建議切換可訪問性屬性
我認為焦點是從bootstrap模態本身被劫持,你可以使用shown
事件並相應地設置焦點。
參考:
Bootstrap為大多數插件的獨特操作提供自定義事件。 通常,它們以不定式和過去的分詞形式出現 - 其中不定式(例如show)在事件開始時觸發,並且其過去的分詞形式(例如顯示)在動作完成時觸發。
從3.0.0開始,所有Bootstrap事件都是命名空間。
所有不定式事件都提供preventDefault功能。 這提供了在動作開始之前停止執行的能力。
碼:
$('#myModal').on('shown.bs.modal', function () {
//your current focus set
});
試試這個......在show modal窗口中
this.$workModal.on('show.bs.modal', (e) => {
$('#workId_input').data('kendoNumericTextBox').focus();
});
在UI ....你需要輸入ID ...
<input id='workId_input', data-bind="kendoNumericTextBox ......">
試試這個..你只需要關閉Bootstrap附帶的事件監聽器。
$('#myModal').on('shown.bs.modal', function() {
$(document).off('focusin.modal');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.