English 中文(简体)
如何在 dojo 数据格中选择后更新行中的内容
原标题:How to update content in Row after selection in dojo datagrid

我创建了一个 dojo 数据格。 每个列都有一个要处理的事项。 当生成网格时, 调用要处理的事项。 现在我要它, 如果用户选择任何行, 就会调用要处理的事项, 并且某些字符串应该附加在选中的行列元素上 。

就像网格是这样的:

COLUMN
-------
a

b

c

现在用户选择第二行, 网格应该更改为 :

COLUMN
-------
a

b SELECTED

c

目前我实施如下:

if(this.grid.selection.selectedIndex !== -1){
  retrun value + "SELECTED";
}else{
 return value;
}

请注意不要在网格商店中添加“ 安全” 字符串 。

问题回答

格式未被锁定到单击 / 选择行。 它仅在单元格内容( 值) 设定后才被执行。 相反, 您想要将焦点移到 RowClicked 上 - 网格组件上的事件。 它像这样工作 :

grid.onRowClick = onRowClickHandler;

我不知道下面的哪些样本能让你 最接近目标 但是在RowClickHandler上可以设置成这样:

function onRowClickHandler(evt) {
    var rows = this.selection.getSelected();
    // perform cell rendering here
    dojo.forEach(rows, function(row) {
       // this row is an item though.. you will have row._O as its index
    });
}

function onRowClickHandler(e) {
   var cellClicked = this.focus.cell
   cellClicked.formatter();
}

然而,您可能发现网格组件中任何地方的可查看数据没有多少引用。 您可以在查询选择器后找到单元格数据, 并通过在每个值上调用文件来更新已视图的 html 。 您需要捕捉先前的选定, 以拆卸您的自定义值设置 。

var prevSelectedRows = [];
function onRowClickHandler(evt) {
    var idx = this.selection.selectedIndex,
        rawRow = dojo.query(".dojoxGridRow:nth-child("+(idx+1)+")", this.domNode)[0],
        self = this;

    // perform resetting of viewable values
    dojo.forEach(prevSelectedRows, function(raw) {
      dojo.query( .dojoxGridCell , raw).forEach(function(cellDOM, i) {
        cellDOM.innerHTML = cellDOM.innerHTML.replace("SELECTED", "");
      });

    });
    prevSelectedRows = []; // reset prev selection
    // look into grid.view.content for methods on this
    // perform setting of viewable values (SELECTED)
    dojo.query( .dojoxGridCell , rawRow).forEach(function(cellDOM, i) {
        // this function might be of interest, lets see how it looks in console
        console.log(self.layout.cells[i].formatter);
        cellDOM.innerHTML = cellDOM.innerHTML + "SELECTED"
    });

    prevSelectedRows.push(rawRow);
}




相关问题
WPF: Adding Button Column to Datagrid

How can I add a Button column to a Datagrid programmatically? I want to do this through code in the code-behind file. Also i want to selectively enable or disable this button based on record (If ...

Silverlight Datagrid RowEditEnded

I have a SL DataGrid that has two columns. I need to be able to catch any change to the a row and save it into an undo stack. I setup the event RowEditEnded and tried to add to the undo stack there. ...

WPF Keep column sorting with Datagrid

I have several datagrid where I need to update the informations. Things is, since more than one person works on the system at the same time, the datagrid need to be refreshed on a regular basis. When ...

热门标签