如何在Dojo数据网格中声明性地右对齐列
我使用html声明性地创建了一个Dojo数据网格。我需要右对齐一列。我试过以下两种方法,但都没用 尝试1 在下面的示例中,将忽略如何在Dojo数据网格中声明性地右对齐列,dojo,dojox.grid.datagrid,Dojo,Dojox.grid.datagrid,我使用html声明性地创建了一个Dojo数据网格。我需要右对齐一列。我试过以下两种方法,但都没用 尝试1 在下面的示例中,将忽略align=“right”,但将width=“100px”添加到每个元素的样式中 <table data-dojo-type="dojox.grid.DataGrid" style="height:100px;"> <thead> <tr> <th field="col1" width="auto">Col
align=“right”
,但将width=“100px”
添加到每个
元素的样式中
<table data-dojo-type="dojox.grid.DataGrid" style="height:100px;">
<thead>
<tr>
<th field="col1" width="auto">Col 1</th>
<th field="col2" width="100px" align="right">Col 2</th>
<th field="col3" width="100px" align="right">Col 3</th>
</tr>
</thead>
</table>
您需要在
元素上使用样式
属性。顾名思义,此属性指定将哪些css样式应用于该列的
s
标记示例:
<body class="claro">
<table data-dojo-type="dojox.grid.DataGrid" style="width:100%" store="myStore">
<thead>
<tr>
<th field="col1" width="auto" align="left">Col 1</th>
<th field="col2" width="100px" align="left">Col 2</th>
<th field="col3" width="100px" align="right" styles="text-align:right;">Col 3</th>
</tr>
</thead>
</table>
</body>
第1列
第2列
第3列
示例js:
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.parser');
dojo.require('dojo.data.ItemFileWriteStore');
dojo.ready(function() {
var data = {
identifier: 'id',
items: []
};
var data_list = [
{
col1: "normal",
col2: false,
col3: 29.91},
{
col1: "important",
col2: false,
col3: 9.33},
{
col1: "important",
col2: false,
col3: 19.34}
];
var rows = 60;
for (var i = 0, l = data_list.length; i < rows; i++) {
data.items.push(dojo.mixin({
id: i + 1
}, data_list[i % l]));
}
myStore = new dojo.data.ItemFileWriteStore({
data: data
});
dojo.parser.parse();
});
dojo.require('dojox.grid.DataGrid');
require('dojo.parser');
require('dojo.data.ItemFileWriteStore');
ready(function()){
风险值数据={
标识符:“id”,
项目:[]
};
变量数据列表=[
{
col1:“正常”,
col2:错,
col3:29.91},
{
col1:“重要”,
col2:错,
col3:9.33},
{
col1:“重要”,
col2:错,
col3:19.34}
];
var行=60;
对于(变量i=0,l=data_list.length;i
我在“使用网格”教程中发现了此属性您希望右对齐什么?专栏本身?还是列中的文本?我放了一个快速的提琴来演示网格与dojo文档()的对应关系,但我认为我不理解您的要求。@Buffalo-我希望列中的文本正确对齐。Col2和Col3具有小数点后两位的数字。我想让小数排成一行。@buffalo-谢谢你的jsfiddle,我没能在那里正确对齐文本,但是汉克,行了!我很尴尬,我已经通过教程创建了所有我通过编程生成的网格,我应该更清楚地知道,也可以简单地以声明格式进行尝试。属性
style
对于添加html元素来说是非常不直观的,这并没有帮助。
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.parser');
dojo.require('dojo.data.ItemFileWriteStore');
dojo.ready(function() {
var data = {
identifier: 'id',
items: []
};
var data_list = [
{
col1: "normal",
col2: false,
col3: 29.91},
{
col1: "important",
col2: false,
col3: 9.33},
{
col1: "important",
col2: false,
col3: 19.34}
];
var rows = 60;
for (var i = 0, l = data_list.length; i < rows; i++) {
data.items.push(dojo.mixin({
id: i + 1
}, data_list[i % l]));
}
myStore = new dojo.data.ItemFileWriteStore({
data: data
});
dojo.parser.parse();
});