How to sort a dojo datagrid cell correctly when fo

2019-09-15 03:28发布

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.

标签: datagrid dojo
1条回答
我只想做你的唯一
2楼-- · 2019-09-15 04:01

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.

查看更多
登录 后发表回答