2017-09-13 82 views
0

我想對鍵值對中有數據的列進行排序。目前我已經實現了使用基於關鍵字Id的自定義排序功能進行排序。在這裏,我想根據不是Id的值進行排序。我怎樣才能做到這一點?任何人都可以幫我解決這個問題嗎?使用jqgrid按列值排序

請查看以下代碼供您參考。

jQuery("#list2").jqGrid({ 
    url: '/LocaleRate/LocaleRates',  
    mtype: 'GET', 
    datatype: "json", 
    colModel: [ 
     { name: 'ID', hidden: true }, 
     { 
      name: 'SourceLocaleId', index: 'SourceLocaleId', edittype: "select", formatter: 'select', 
      editoptions: { value: newLocalelist }, 
      sorttype: function (value, rowObject) { 
       return rowObject.SourceLocaleId; 
      }, 

     }, 
     { 
      name: 'LocaleId', index: 'LocaleId', edittype: "select", formatter: 'select', editoptions: { value: newLocalelist }, 
      sorttype: function (value, rowObject) { 
       return rowObject.LocaleId; 
      }, 
     }] )} 

回答

0

我在這將返回各自的值&然後將jqGrid的執行排序Sorttype自定義函數發送cellvalue即標識。

請在下面找到您參考以下步驟:

jQuery("#list2").jqGrid({ 

    url: '/LocaleRate/LocaleRates', 
    mtype: 'GET', 
    datatype: "json", 
    colModel: [ 
     { name: 'ID', hidden: true }, 
     { 
      name: 'SourceLocaleId', label: 'Source Locale', index: 'SourceLocaleId', edittype: "select", formatter: 'select', editoptions: { value: LoadData(LocaleURL) }, 
      editrules: { required: true }, 
      sorttype: function (value) { 
       return sortData(value, 'SourceLocaleId'); 
      }, 
     }, 
     { 
      name: 'LocaleId', label: 'Locale', index: 'LocaleId', width: 130, align: "left", editable: true, edittype: "select", formatter: 'select', editoptions: { value: LoadData(LocaleURL) }, editrules: { required: true }, 
      sorttype: function (value) { 
       return sortData(value, 'LocaleId'); 
      }, 
     }] 
    }) 

請找SortData功能如下:

function sortData(key, columnName) { 

    var textvalue, getData = LocaleData ; 

    for (var i = 0; i < getData.length; i++) { 
     if (getData[i].Value == key) { 
      textvalue = getData[i].Text; 
     } 
    } 
    return textvalue; 
} 

注: localedata等包含鍵值對的數據。在這裏,我將匹配鍵與值返回它。