How to sort a dojo datagrid cell correctly when formatter accesses other row content

十年热恋 提交于 2019-12-11 15:38:53

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7359539/how-to-sort-a-dojo-datagrid-cell-correctly-when-formatter-accesses-other-row-con

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!