1

我有一个看起来像这样的可编辑列定义......

    {
        name: 'recType',           
        label: 'recType',           
        index: 'recType',                           
        width: 100, 
        fixed: true,  
        keys:  true,     
        editable: true, 
        edittype: "select",  
        editoptions: {value: rectypelist}, 
        stype: 'select',
        formatter: 'select'
    }

注意:“rectypelist”是 键:值对的列表...例如,

    1:apple
    4:pear
    2:orange
    3:banana

我需要能够按列表框条目的值(即,已正确显示在列中)对该列进行排序。

正如上面配置的那样,排序是在列表框条目的“键”上执行的,而不是条目的“值”(条目的“值”是实际显示在网格中的内容)。

- 因此,当用户对列进行排序时,他们没有收到预期的行为。

问题:如何配置此列定义,以便对列表框条目的“显示”值而不是“键”值执行排序?

谢谢你的帮助

4

1 回答 1

1

这是我解决问题的方法...

好吧,显然当您的列被定义为下拉/列表框(包含键:值对的行)时......

喜欢,

    1:rectypeA
    4:rectypeB
    2:rectypeC
    3:rectypeD

...然后,在列定义中,您需要为“sorttype”参数分配一个函数,该参数将返回您要排序的值... (在这种情况下,我想使用“key”中的“value” :value" 对) ...

--由于我希望我的列按“”排序(即,这是我要解决的问题!),我显然必须使用函数来返回与“键”对应的“” ”。

在下面的示例中,我创建了一个名为“rectypes”的映射,其中包含键:值对。

--在函数中,我只是使用“rectypes”映射来提取并返回我想要在排序中使用的值(与“key”相关联)

IE,

    -
    -
    -
    {
        name: 'recType',           
        label: 'recType',           
        index: 'recType',                                               
        width: 100, 
        fixed: true,  
        keys:   true, 
        sortable:true,  
        //...the function below returns the VALUE of 
        //   the KEY:VALUE pair that is to be used for the sort
        sorttype: function (cellvalue ) {return rectypes[cellvalue];},
        editable: true, 
        edittype: "select",  
        editoptions: {value: rectypelist}, 
        stype: 'select', 
        formatter: 'select'
    },    
    -
    -
    -

注意:“cellvalue”是自动提供的。在示例中,我创建了一个名为“rectypes”的映射,其中包含“key:value”对,使我能够提取并返回我想要用于排序的值。

于 2013-08-13T19:40:36.313 回答