Description:
I've encountered an issue with grouping functionality in a grid that uses nested field. Here's the setup:
- I have two stores:
teamStore
andplayersStore
. - There's a relation between these stores: each team record has an array of players.
- I've created a grid with two columns: "Player" and "Team".
- The grid is assigned to
playerStore
. - The "Player" column is mapped to the record's
name
field. - The "Team" column is mapped to the record's related
team.name
field. - I've defined a
groupRenderer
function for the "Team" column to customize the group header.
Bug:
When I try to group by the "Team" column, the groupRenderer function is not being called, and the custom group header is not displayed.
Finding:
I've discovered that the group header record's meta
object contains a groupField
value of "name" instead of the expected "team.name".
Video:
https://www.loom.com/share/20f3f7201e9b4b178de065d539522e5a
Code Snippet:
import { Grid, Store, Model } from '../../build/grid.module.js?478334';
import shared from '../_shared/shared.module.js?478334';
class Player extends Model {
static relations = {
// Define a relation between a player and a team
team : {
foreignKey : 'teamId',
foreignStore : 'teamStore',
relatedCollectionName : 'players'
}
}
}
class Team extends Model {
get playersValue() {
return this.players?.map((player) => player.name)
}
}
const teamStore = new Store({
modelClass: Team,
data : [
{ id : 1, name : 'Brynas' },
{ id : 2, name : 'Leksand' }
]
});
const playerStore = new Store({
modelClass : Player,
// Matches foreignStore, allowing records of playerStore to find the related store
teamStore,
data : [
// teamId is specified as foreignKey, will be used to match the team
{ id : 1, name : 'Nicklas Backstrom', teamId : 1 },
{ id : 2, name : 'Elias Lindholm', teamId : 1 },
{ id : 3, name : 'Filip Forsberg', teamId : 2 }
],
});
const grid = new Grid({
appendTo : 'container',
features : {
group: true,
},
columns : [
{
text : 'Player',
field : 'name',
flex : 1
},
{
text : 'Team',
field : 'team.name',
flex : 1,
groupRenderer(renderData) {
console.log("===Team Group Renderer ===", renderData);
return {
class : {
big : true,
small : false
},
children : [
renderData.groupRowFor
]
};
}
},
],
store : playerStore
});