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

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

{ 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 

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

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

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

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

谢谢你的帮助

以下是我解决问题的方法……

好吧,显然当你的列定义为dropdown / listbox(包含键:值对的行)时……

喜欢,

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

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

– 因为我希望我的列按“ ”排序(即,这是我试图解决的问题!) ,我显然必须使用一个函数来返回对应于“键”的“ ” ”。

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

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

  - - - { 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”对,这使我可以提取并返回我想要用于排序的值。