如何在jqgrid中实现大写转换 [英] how to implement uppercase conversion in jqgrid
问题描述
Producr代码只能包含大写字符。如果输入小写字符,jqgrid不会将它们转换为大写,则没有这样的选项。
如何在文本字段的内联和表单编辑模式下强制jqgrid中输入字符的大写转换?
Producr codes can contain only uppercase charcters. If lowercase characters are enterd, jqgrid does not convert them to upper case, there is not such option. How to force uppercase conversion of entered characters in jqgrid in inline and form edit modes for text fields ?
更新
我在如何在ASP.NET文本框中强制输入大写?最后一个答案。此代码在keypress中以大写形式更改输入的字符。通过向jqgrid编辑控件添加keyprees事件处理程序来使用它是否合理?
I found code in How can I force input to uppercase in an ASP.NET textbox? last answer . This code changes entered character in uppercase in keypress. Is it reasonable to use this by adding keyprees event handler to jqgrid editing controls?
function ToUpper() {
// So that things work both on FF and IE
var evt = arguments[0] || event;
var char = String.fromCharCode(evt.which || evt.keyCode);
// Is it a lowercase character?
if (/[a-z]/.test(char)) {
// convert to uppercase version
if (evt.which) {
evt.which = char.toUpperCase().charCodeAt(0);
}
else {
evt.keyCode = char.toUpperCase().charCodeAt(0);
}
}
return true;
}
使用如下:
<asp:TextBox ID="txtAddManager" onKeyPress="ToUpper()" runat="server"
Width="84px" Font-Names="Courier New"></asp:TextBox>
推荐答案
首先你可以使用CSS样式 text-transform:大写
到显示用户输入的大写数据:
First of all you can use CSS style text-transform: uppercase
to display the data typed by the user in uppercase:
editoptions: { dataInit: function (el) { $(el).css('text-transform', 'uppercase'); }}
该设置不会更改数据本身。所以你必须另外做相应的修改。在表单编辑的情况下,您可以使用 beforeSubmit
。例如,让我们为您提供列'name'
,您需要保持大写。然后首先在 dataInit
中添加 text-transform:uppercase
的设置(见上文)并添加
The setting will not change the data itself. So you have to make the corresponding modification additionally. In case of form editing you can use beforeSubmit
. For example, let us you have column 'name'
which you need to hold uppercase. Then you first add the setting of text-transform: uppercase
in dataInit
(see above) and add
beforeSubmit: function (postData) {
postData.name = postData.name.toUpperCase();
return [true, ''];
}
如果是内联编辑,则没有 beforeSubmit
回调函数。所以你可以使用 serializeRowData
如果你有远程数据:
In case of inline editing there are no beforeSubmit
callback function. so you can use serializeRowData
if you have remote data:
serializeRowData: function (postData) {
postData.name = postData.name.toUpperCase();
return postData;
}
如果使用 editurl:'clientArray'
你可以修复 aftersavefunc
参数 editRow
和 saveRow
:
In case of usage editurl: 'clientArray'
you can fix the data in aftersavefunc
parameter of editRow
and saveRow
:
aftersavefunc: function (rowid) {
var $grid = $(this),
newName = $grid.jqGrid("getCell", rowid, 'name');
$grid.jqGrid("setCell", rowid, 'name', newName.toUpperCase());
}
参见演示。
这篇关于如何在jqgrid中实现大写转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!