extjs 两种对齐方式在同一列
extjs two types of alignment in the same column
我有一份报告,需要以不同方式对齐列。我需要将具有数字值的行右对齐,并将具有文本的行左对齐。
对于这样的问题有没有什么配置/功能,或者我应该使用CSS?
你可以在列渲染器上做你想做的,像那样改变对齐 属性 并做你需要的计算:
renderer:function(val,cell){
if(parseInt(val))
cell.align='right';
return val;
}
如果您的文本仅由没有任何数字的单词组成,parse int 将起作用,在您的情况下,您可以检查字符串是否只有带有正则表达式的数字,如下所示:
renderer:function(val,cell){
if(val.match(/^[0-9]+$/))
cell.align='right';
else
cell.align='left';
return val;
}
查看 phone 列渲染器。
[更新]
抱歉没有阅读你的 Ext 版本,在你的情况下你可以像这样使用我的函数:
我还用数字中的点更新了案例。
renderer:function(val,cell){
if(val.match(/^[0-9]*\.?[0-9]*$/))
cell.style='text-align:right;';
else
cell.style='text-align:left;';
return val;
}
我有一份报告,需要以不同方式对齐列。我需要将具有数字值的行右对齐,并将具有文本的行左对齐。
对于这样的问题有没有什么配置/功能,或者我应该使用CSS?
你可以在列渲染器上做你想做的,像那样改变对齐 属性 并做你需要的计算:
renderer:function(val,cell){
if(parseInt(val))
cell.align='right';
return val;
}
如果您的文本仅由没有任何数字的单词组成,parse int 将起作用,在您的情况下,您可以检查字符串是否只有带有正则表达式的数字,如下所示:
renderer:function(val,cell){
if(val.match(/^[0-9]+$/))
cell.align='right';
else
cell.align='left';
return val;
}
查看 phone 列渲染器。
[更新]
抱歉没有阅读你的 Ext 版本,在你的情况下你可以像这样使用我的函数:
我还用数字中的点更新了案例。
renderer:function(val,cell){
if(val.match(/^[0-9]*\.?[0-9]*$/))
cell.style='text-align:right;';
else
cell.style='text-align:left;';
return val;
}