问题描述
我有一个可编辑的列定义,看起来像这样...
I have an editable column definition that looks like this...
{
name: 'recType',
label: 'recType',
index: 'recType',
width: 100,
fixed: true,
keys: true,
editable: true,
edittype: "select",
editoptions: {value: rectypelist},
stype: 'select',
formatter: 'select'
}
注意:"rectypelist"是 key:value 对的列表...例如
Note: "rectypelist" is a list of key:value pairs...e.g.,
1:apple
4:pear
2:orange
3:banana
我需要能够通过列表框条目的值(即已经正确显示在该列中)对该列进行排序.
I need to be able to sort this column by the listbox entry's value (i.e., which is already correctly displayed in the column).
根据上面的配置,排序是根据列表框条目的键"而不是条目的值"(条目的值"实际上是在网格中显示的)执行的.
As it is configured, above, the sort is performed upon the listbox entry's "key", rather than the entry's "value" (the entry's "value" is what actually displays in the grid).
-因此,当用户对列进行排序时,他们没有收到预期的行为.
-So, therefore, when the user sorts the column they do not received the expected behavior.
问题::如何配置此列定义,以便对列表框条目的显示"值而不是键"值进行排序?
QUESTION: How can I configure this column definition so that the sort is performed on the listbox entry's "display" value, rather than the "key" value?
感谢您的帮助
推荐答案
这是我解决问题的方法...
好吧,很显然,当您将列定义为下拉列表/列表框(包含键:值对的行)...
Here's how I solved the issue...
Well, apparently when your column is defined as dropdown/listbox (containing rows of key:value pairs)...
喜欢
1:rectypeA
4:rectypeB
2:rectypeC
3:rectypeD
...然后,在列定义中,您需要为"sorttype"参数分配一个函数,该函数将返回您要对之排序的值... (在这种情况下,我想使用"键:值"对中的值") ...
...then, in the column definition, you need assign a function to the "sorttype" parameter that will return the value you want to sort on... (in this case I want to use the "value" from the "key:value" pair)...
-因为我 不 希望我的列按"键" 排序(即,这是问题所在我正在尝试解决!),显然我必须使用一个函数来返回与键"相对应的"值".
--Since I don't want my column sorted by the "key" (i.e., this is the problem I am trying to solve!), I apparently have to use a function to return the "value" that corresponds to the "key".
在下面的示例中,我创建了一个名为"rectypes"的映射,其中包含 key:value 对.
In the example, below, I've created a map called "rectypes" that contains key:value pairs.
-在函数中,我仅使用"rectypes"映射来提取并返回要在排序中使用的值(与"key"关联)
--In the function, I simply use the "rectypes" map to extract and return the value (associated with the "key") that I want used in the sort
即
-
-
-
{
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'
},
-
-
-
注意:单元值"是自动提供的.在示例中,我创建了一个名为"rectypes"的映射,其中包含"key:value"对,这使我可以提取并返回要用于排序的值.
NOTE: "cellvalue" is supplied auto-magically. In the example I created a map called "rectypes" containing the "key:value" pairs that make it possible for me to extract and return the value that I want to be used for sorting.
这篇关于如何配置此JQGrid列定义,以便对列表框条目'" display&"进行排序.值,而不是& quot;键& quot;值价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!