Jquery 如何配置此JQGrid列定义,以便对列表框条目执行排序';s";“显示”;价值,而不是;“关键”;价值

Jquery 如何配置此JQGrid列定义,以便对列表框条目执行排序';s";“显示”;价值,而不是;“关键”;价值,jquery,jqgrid,Jquery,Jqgrid,我有一个可编辑的列定义,如下所示 { name: 'recType', label: 'recType', index: 'recType', width: 100, fixed: true, keys: true, editable: true,

我有一个可编辑的列定义,如下所示

    {
        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
我需要能够根据listbox条目的值(即,该值已正确显示在列中)对该列进行排序

按照上面的配置,排序是根据列表框条目的“键”而不是条目的“值”(条目的“值”是网格中实际显示的内容)执行的

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

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

谢谢你的帮助

以下是我解决问题的方法。。。 显然,当您的列被定义为dropdown/listbox(包含键:值对的行)时

…然后,在列定义中,需要为“sorttype”参数指定一个函数,该参数将返回要排序的值。。。(在本例中,我希望使用“key:value”对中的“value)

--由于我不想让我的列按“键”排序(也就是说,这就是我试图解决的问题!),我显然必须使用一个函数返回与“键”对应的“值”

在下面的示例中,我创建了一个名为“矩形”的映射,其中包含key:value

--在函数中,我只需使用“矩形”映射来提取并返回我希望在排序中使用的值(与“键”关联)

i、 e

    -
    -
    -
    {
        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”是自动神奇地提供的。在这个示例中,我创建了一个名为“矩形”的映射,其中包含“key:value”对,这使我能够提取并返回要用于排序的值

下面是我如何解决这个问题的。。。 显然,当您的列被定义为dropdown/listbox(包含键:值对的行)时

…然后,在列定义中,需要为“sorttype”参数指定一个函数,该参数将返回要排序的值。。。(在本例中,我希望使用“key:value”对中的“value)

--由于我不想让我的列按“键”排序(也就是说,这就是我试图解决的问题!),我显然必须使用一个函数返回与“键”对应的“值”

在下面的示例中,我创建了一个名为“矩形”的映射,其中包含key:value

--在函数中,我只需使用“矩形”映射来提取并返回我希望在排序中使用的值(与“键”关联)

i、 e

    -
    -
    -
    {
        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”是自动神奇地提供的。在这个示例中,我创建了一个名为“矩形”的映射,其中包含“key:value”对,这使我能够提取并返回要用于排序的值