2013-07-23 23 views
0

我有一个如下所示的jqxGrid,我想限制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个字符。如何实现它?

回答

1

对于这一点,你必须使用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; 
       } 
} 
0

该演示使用列的“验证”功能: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对象。