【问题标题】:Dynamically changing color of a cell in Dojo grid based on change of value根据值的变化动态改变 Dojo 网格中单元格的颜色
【发布时间】:2014-05-19 09:01:23
【问题描述】:

我有一个道场网格,主要有 4 列。网格最初是空的。

下面是我的网格布局

var gridLayout = [{
                    defaultCell: { width: '8%', editable: true, type: dojox.grid.cells._Widget, styles: 'text-align: right;'  },
                    rows: [
                        { name: 'Item Id', field: 'ItemId',hidden:true},
                        { name: 'Type', field: 'LineType', width: '8%',  type: dojox.grid.cells.Select,styles: 'text-align: center;'},
                        { name: 'Amount', field: 'Amount', width: '8%', styles: 'text-align: center;', type: dojox.grid.cells.TextBox},
                        { name: 'Code', field: 'Code', width: '8%', styles: 'text-align: center;',formatter:changeCodeColor, type: dojox.grid.cells.TextBox}
                    ]
                }];

单击表单中的添加行项目按钮时,我从服务器获取项目,金额单元格中的值为空,但类型和代码是自动填充的。 如果用户更改代码单元格中的值,我需要更改代码的颜色。 下面是我写的函数

function changeCodeColor(code, rowIndex, cell) 
{
    var codeDetails = validateCode(code)
    if(!codeDetails)
    {
        cell.customStyles.push('color:red');;
    }
    return code; 
  }

validateCode 函数在服务器中检查代码是否有效。如果代码无效或不可用,我将颜色设置为红色。

但问题是每次填充值时都会执行此代码(即手动更改以及系统自动添加时)。 只有当用户手动更改时,我才需要进行验证。

任何帮助都会很有用

【问题讨论】:

    标签: dojo grid


    【解决方案1】:

    Formatter 用于定义应如何显示商店中的数据。对于事件处理程序,您应该像这样使用 DataGrid 中的 onCellClick 事件,

    var grid = new Grid({
        store: store,
        selectionMode: 'single',
        structure: [[
            { field: 'name', name: 'Name' }
        ]]}, dojo.byId("grid"));
    grid.startup();
    
    dojo.connect(grid, "onCellClick", function(e) {
        var dataItem = grid.selection.getSelected();
        console.dir(dataItem);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      • 2023-03-09
      • 1970-01-01
      • 2017-05-20
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多