当格式化程序访问其他行内容时,如何正确排序dojo datagrid单元格 [英] How to sort a dojo datagrid cell correctly when formatter accesses other row content

查看:151
本文介绍了当格式化程序访问其他行内容时,如何正确排序dojo datagrid单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对dojo datagrid(增强版)排序问题,因为有问题的格式化程序通过rowIndex访问同一数据行的第二个值。



当此列排序时,底层数组不会更改,并且行索引访问与之前相同的行(第二个值保留),而该值正确排序。



这是我的意思的一个例子:



列国家显示一个国家的名称和与国家相对应的标志。
country.name是主要值,country.iso是第二个值。



列格式化程序的定义如下:

  var formatCountryName = function(value,rowIndex){
var iso = this.grid.store.getItem(rowIndex).iso;
return'< img src =../ flags / flag _'+ iso +'。png>'+ value;
};

没有排序网格将显示



<$ p澳大利亚
(比利时国旗)
(加拿大国旗)加拿大

当相反方向排列此列时,网格将显示

 (澳大利亚国旗)加拿大
(比亚国旗)比利时
(加拿大国旗)澳大利亚

因为底层数组没有更改其顺序,行索引
仍然访问相同的country.iso。



我将如何访问国家/地区的排序值.iso,所以
标志对应于国家名称。



其实我在这个应用程序的关键部分有相同的错误是
重要提示显示对应于同一数据行的其他值,但
我只通过这个相当小的眼睛糖果发现了错误。

解决方案

尝试一下:



var columnNameForIso =iso;
var iso = grid.store.getValue(grid.getItem(rowIndex),columnNameForIso);



将您的columnNameForIso替换为实现的任何内容。 / p>

I have a problem sorting a dojo datagrid (enhanced version) correctly, because the formatter for the column in question accesses a 2nd value of the same data row via rowIndex.

When this column is sorted the underlying array does not change and the row Index accesses the same row as before (2nd value remains) while the value is sorted correctly.

Here is an example of what I mean:

The column "country" displays the name of a country and a flag corresponding to the nation. country.name is the primary value and country.iso is the second value.

The column formatter is defined the following way:

var formatCountryName = function(value,rowIndex){
  var iso = this.grid.store.getItem(rowIndex).iso;
  return '<img src="../flags/flag_'+iso+'.png">'+value;
};

Without sorting the grid would display

  (Australian Flag) Australia
  (Begian Flag) Belgium
  (Canadian Flag) Canada

When sorting this column in the opposite direction the grid would display

  (Australian Flag) Canada
  (Begian Flag) Belgium
  (Canadian Flag) Australia

because the underlying array did not change its order and the row index still accesses the same country.iso.

How would I go about accessing the sorted value of country.iso, so the flag corresponds to the nations name.

Actually I have the same error in critical parts of this application were important hints are displayed corresponding to other values of the same data row, but I only found out about the error through this rather trivial eye candy.

解决方案

Give this a try :

var columnNameForIso = "iso"; var iso = grid.store.getValue(grid.getItem(rowIndex), columnNameForIso);

Replacing your columnNameForIso with whatever it is for your implementation.

这篇关于当格式化程序访问其他行内容时,如何正确排序dojo datagrid单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆