如何在ag-grid中为特定列自定义分组值?

时间:2020-08-07 13:22:00

标签: ag-grid

我有一个ag-grid企业组件,其中显示了这样的列表:

#include <stdio.h>

typedef struct {
    int a;
    int b;
    double d;
} MyStruct;

typedef MyStruct MS_t[1];
typedef MyStruct* MS_ptr;

int main()
{
    MS_t mt;
    MS_ptr mp;
    printf("Size of type = %zu; Size of pointer = %zu\n\n", sizeof(MS_t), sizeof(MS_ptr));

    mt->a = 1; mt->b = 2; mt->d = 3.141; // Good - "mt" can be used as a pointer to first (only) element of the array.
//  mp->a = 3; mp->b = 7; mp->d = 3.141; // UNDEFINED BEHAVIOUR - mp doesn't point to anything.

    MyStruct ms1, ms2 = { 3, 8, 42.42 };
    mp = &ms1;
    mp->a = 2; mp->b = 4; mp->d = 2.718; // OK - mp now points to a valid structure (ms1)

    printf("MT: %d %d %f\n", mt->a, mt->b, mt->d);
    printf("MP: %d %d %f\n", mp->a, mp->b, mp->d);

    // Let's try to change addresses:
    mp = &ms2; // We can change what "mp" points to whenever we like
    printf("MP: %d %d %f\n", mp->a, mp->b, mp->d); // Different address -> different structure -> different data!
//  mt = &ms2; // ERROR: array type 'MS_t' (aka 'MyStruct [1]') is not assignable

    mp = mt; // We can even use "mt" as an address to assign to "mp"
    printf("MP: %d %d %f\n", mp->a, mp->b, mp->d); // This shows the 'first' data set values

    return 0;
}

当用户选择将结果按第1列分组时,我希望ag-grid仅使用前三个字母进行分组,而不是完整值:

Column 1  Column 2  Column 3
--------  --------  ----------
ABC123    4         Category 1
ABC456    5         Category 2
DEF789    1         Category 1
DEF012    8         Category 3

我该怎么做?

据我了解,group cell renderer仅影响组的显示方式,而不会更改组的实际值。

1 个答案:

答案 0 :(得分:1)

找到了。我可以使用keyCreator来做到这一点:

const colDef = [
    {
        headerName: 'Column 1',
        ...
        rowGroup: true,
        keyCreator: p => p.value.substr(0, 3)
    },
    ...
]