初始化界面,发现编辑datagrid,不能输入小数点。
var arrColumnsCNT = [[ { title: ‘毛重‘, field: ‘GrossWeight‘, halign: ‘center‘, width: 60, sortable: true, frozen: true, editor: { type: ‘numberbox‘, options:{precision:2} } } ]]; function DefDataGridCNT() { objDataGridCNT = $(‘#tableDataGridCNT‘).datagrid({ selectOnCheck: false, checkOnSelect: false, singleSelect: true, rownumbers: true, striped: true, remoteSort: false, multiSort: true, scrollbarSize: 0, fitColumns: true, height: 250, width: 1000, onClickCell: onClickCellCNTGrid, columns: arrColumnsCNT, onBeginEdit:function(rowIndex){ var editors = $(‘#tableDataGridCNT‘).datagrid(‘getEditors‘, rowIndex); var n1 = $(editors[8].target); var n2 = $(editors[9].target); var n3 = $(editors[12].target); n1.add(n2).numberbox({ onChange:function(){ var cost = Number(n1.numberbox(‘getValue‘))+Number(n2.numberbox(‘getValue‘)); n3.numberbox(‘setValue‘,cost); } }) }, onAfterEdit: function (index, row, changes) { autoSetValue(); } }); };
解决办法:页面初始化加入如下代码
//解决numberbox小数点问题 (function($){ $.fn.numberbox.defaults.filter = function(e){ var opts = $(this).numberbox(‘options‘); var s = $(this).numberbox(‘getText‘); if (e.which == 45){ //- return (s.indexOf(‘-‘) == -1 ? true : false); } var c = String.fromCharCode(e.which); if (c == opts.decimalSeparator){ return (s.indexOf(c) == -1 ? true : false); } else if (c == opts.groupSeparator){ return true; } else if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8) { return true; } else if (e.ctrlKey == true && (e.which == 99 || e.which == 118)) { return true; } else { return false; } } })(jQuery);
时间: 2024-10-11 09:39:21