我有一个如下所示的jqxGrid,我想限制jqxGrid中的字符数。
columns : [ {
text :
‘Type’,datafield : ‘type’, width : 150, align : ‘center’,cellsalign : ‘left’, editable : false
}, {
text :
‘Phase’,datafield : ‘phase’, width : 150, align : ‘center’,cellsalign : ‘left’, editable : false
},{
text :
‘Phase Description’,datafield : ‘phaseDescription’, width : 150, align : ‘center’,cellsalign : ‘left’, editable : false
},{
text :
‘Custom Phase’, datafield : ‘customPhase’, width : 150, align : ‘center’, cellsalign : ‘left’
}对于“自定义阶段”一栏,我需要将用户输入限制为10个字符。如何做到这一点?
发布于 2013-09-17 16:02:17
为此,您必须使用jqwidget验证,并在视图文件中包含文件jqxvalidator.js,并在列中使用以下代码:
columns : [ {
text :
‘Type’,datafield : ‘type’, width : 150, align : ‘center’,cellsalign : ‘left’, editable : false
}, {
text :
‘Phase’,datafield : ‘phase’, width : 150, align : ‘center’,cellsalign : ‘left’, editable : false
},{
text :
‘Phase Description’,datafield : ‘phaseDescription’, width : 150, align : ‘center’,cellsalign : ‘left’, editable : false
},{
text :
‘Custom Phase’, datafield : ‘customPhase’, width : 150, align : ‘center’, cellsalign : ‘left’,
validation: function (cell, value)
{
if (value.length > 10) {
return { result: false, message: "character should be maximum 10" };
}
return true;
}
}发布于 2013-09-17 17:20:34
这个示例使用了列的“验证”函数:cellediting.htm。
validation: function(cell, value)
{
if (value.toString().length > 10)
{
return { result: false, message: "entered text should be less than 10 characters"}
}
return true;
}toString()是必需的,因为值可以是Number或Date对象。
https://stackoverflow.com/questions/17811190
复制相似问题