2012-11-22 45 views
0

對不起,但我不明白我做錯了什麼。我從服務器獲取json並希望對列應用排序。渲染網格後,我可以看到標頭欄看起來像排序的,但數據的靜態未排序排序不適用於數據類型jsonstring

enter image description here

我對電網產生的javascript:

var gridDefinition = window['personalExpensesGridModel']; 

gridDefinition.sortname = 'Type'; 
gridDefinition.sortorder = 'desc'; 
grid.jqGrid(gridDefinition); 

Sorttype爲每個列定義。在這裏你可以看到對象進行配置:

enter image description here

UPDATE1

{ 
    "autowidth": true, 
    "gridid": "RegExpGeneral", 
    "url": null, 
    "datatype": "jsonstring", 
    "colModel": [ 
     { 
      "key": false, 
      "name": "Status", 
      "label": " ", 
      "settingsCaption": "Status", 
      "resizable": false, 
      "fixed": true, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 25, 
      "hidden": false, 
      "columnSettingsType": "alwaysvisible" 
     }, 
     { 
      "key": false, 
      "name": "Type", 
      "label": "<span title='???'>Type</span>", 
      "settingsCaption": "Type", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 194, 
      "hidden": false, 
      "columnSettingsType": "alwaysvisible" 
     }, 
     { 
      "key": false, 
      "name": "ExpenseCategory", 
      "label": "&nbsp;", 
      "settingsCaption": "ExpenseCategory", 
      "resizable": false, 
      "fixed": true, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 25, 
      "hidden": false, 
      "columnSettingsType": "alwaysvisible" 
     }, 
     { 
      "key": false, 
      "name": "Description", 
      "label": "<span title='???'>Description</span>", 
      "settingsCaption": "Description", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 91, 
      "hidden": false, 
      "columnSettingsType": "alwaysvisible" 
     }, 
     { 
      "key": false, 
      "name": "Customer", 
      "label": "<span title='???'>Customer</span>", 
      "settingsCaption": "Customer", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 157, 
      "hidden": false, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "Project", 
      "label": "<span title='???'>Project</span>", 
      "settingsCaption": "Project", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 250, 
      "hidden": false, 
      "columnSettingsType": "alwaysvisible" 
     }, 
     { 
      "key": false, 
      "name": "Activity", 
      "label": "<span title='???'>Activity</span>", 
      "settingsCaption": "Activity", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 197, 
      "hidden": false, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "NotesOrAttendees", 
      "label": "&nbsp;", 
      "settingsCaption": "NotesOrAttendees", 
      "resizable": false, 
      "fixed": true, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 25, 
      "hidden": false, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "Number", 
      "label": "<span title='???'>Kms</span>", 
      "settingsCaption": "Kms", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "Global.Grid.SortNumbers", 
      "frozen": false, 
      "width": 103, 
      "hidden": false, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "IntendDate", 
      "label": "<span title='???'>Date</span>", 
      "settingsCaption": "Date", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 50, 
      "hidden": true, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "CostInCurrency", 
      "label": "<span title='???'>Original Amount</span>", 
      "settingsCaption": "Original Amount", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "Global.Grid.SortNumbers", 
      "frozen": false, 
      "width": 80, 
      "hidden": true, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "Vat", 
      "label": "<span title='???'>Vat</span>", 
      "settingsCaption": "Vat", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "Global.Grid.SortNumbers", 
      "frozen": false, 
      "width": 80, 
      "hidden": true, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "CostExchangeRate", 
      "label": "<span title='???'>Exchange Rate</span>", 
      "settingsCaption": "Exchange Rate", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "Global.Grid.SortNumbers", 
      "frozen": false, 
      "width": 40, 
      "hidden": true, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "Compensation", 
      "label": "<span title='???'>Compensation</span>", 
      "settingsCaption": "Compensation", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "Global.Grid.SortNumbers", 
      "frozen": false, 
      "width": 65, 
      "hidden": false, 
      "columnSettingsType": "alwaysvisible" 
     }, 
     { 
      "key": false, 
      "name": "CustomerPrice", 
      "label": "<span title='???'>Customer price</span>", 
      "settingsCaption": "Customer price", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "Global.Grid.SortNumbers", 
      "frozen": false, 
      "width": 80, 
      "hidden": true, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "Chargeability", 
      "label": "<span title='???'>Not chargeable</span>", 
      "settingsCaption": "Not chargeable", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 20, 
      "hidden": true, 
      "columnSettingsType": "regular" 
     }, 
     { 
      "key": false, 
      "name": "Actions", 
      "label": "&nbsp;", 
      "settingsCaption": "Actions", 
      "resizable": false, 
      "fixed": true, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": 25, 
      "hidden": false, 
      "columnSettingsType": "noconfig" 
     }, 
     { 
      "key": true, 
      "name": "TransId", 
      "label": "&nbsp;", 
      "settingsCaption": "TransId", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": null, 
      "hidden": true, 
      "columnSettingsType": "noconfig" 
     }, 
     { 
      "key": false, 
      "name": "IsValid", 
      "label": "&nbsp;", 
      "settingsCaption": "IsValid", 
      "resizable": true, 
      "fixed": false, 
      "sortable": true, 
      "sorttype": "text", 
      "frozen": false, 
      "width": null, 
      "hidden": true, 
      "columnSettingsType": "noconfig" 
     } 
    ], 
    "altRows": true, 
    "width": null, 
    "height": 415, 
    "shrinkToFit": true, 
    "jsonReader": { 
     "repeatitems": false 
    }, 
    "datastr": { 
     "userdata": null, 
     "total": 1, 
     "page": 1, 
     "records": 78, 
     "rows": [ 
      { 
       "Status": "<img src='/PXControl/Content/images/expenses/grid/pe_status_saved.png' alt='SA' title='Saved' />", 
       "Type": "Travelcompclass U1 (TEST) (U1)", 
       "ExpenseCategory": "<img src='/PXControl/Content/images/expenses/grid/expenses.png' alt='E' title='General' />", 
       "Description": "", 
       "Customer": "Construction Enterprice", 
       "Project": "301952 - Syncron International AB, löpande konsultation PX Control.", 
       "Activity": "10 - Ej debiterbar tid hos kund", 
       "NotesOrAttendees": "", 
       "Number": "", 
       "IntendDate": "", 
       "CostInCurrency": "", 
       "Vat": "0,00", 
       "CostExchangeRate": "", 
       "Compensation": "3,00", 
       "CustomerPrice": "0,00", 
       "Chargeability": "No", 
       "Actions": "<a class=\"edit-link\" data-ajax=\"true\" data-ajax-method=\"POST\" data-ajax-mode=\"replace\" data-ajax-success=\"Global.PersonalExpenses.afterAjax()\" data-ajax-update=\"#px-expenses-page-container\" href=\"/PXControl/Reg/TimeExpenses/GeneralExpense?period=201152%20%20&amp;versionCode=U&amp;transId=33024&amp;statusFilter=All&amp;doSubmit=False\">edit</a><a data-ajax=\"true\" data-ajax-begin=\"Global.PersonalExpenses.saveFormData()\" data-ajax-method=\"POST\" data-ajax-mode=\"replace\" data-ajax-success=\"Global.PersonalExpenses.afterAjax()\" data-ajax-update=\"#px-expenses-page-container\" href=\"/PXControl/Reg/TimeExpenses/Delete?period=201152%20%20&amp;versionCode=U&amp;transId=33024&amp;category=General&amp;page=General\"><img src=\"/PXControl/Content/images/expenses/grid/delete_normal.png\" /></a>", 
       "TransId": "33024", 
       "IsValid": "1" 
      }, 
      { 
       "Status": "<img src='/PXControl/Content/images/expenses/grid/pe_status_saved.png' alt='SA' title='Saved' />", 
       "Type": "Travelcompclass U1 (TEST) (U1)", 
       "ExpenseCategory": "<img src='/PXControl/Content/images/expenses/grid/expenses.png' alt='E' title='General' />", 
       "Description": "", 
       "Customer": "Search Engine Marketing Company", 
       "Project": "301395 - Utbildning Visma Business", 
       "Activity": "ANV - .", 
       "NotesOrAttendees": "", 
       "Number": "", 
       "IntendDate": "", 
       "CostInCurrency": "", 
       "Vat": "0,00", 
       "CostExchangeRate": "", 
       "Compensation": "1 000,00", 
       "CustomerPrice": "1000,00", 
       "Chargeability": "Yes", 
       "Actions": "<a class=\"edit-link\" data-ajax=\"true\" data-ajax-method=\"POST\" data-ajax-mode=\"replace\" data-ajax-success=\"Global.PersonalExpenses.afterAjax()\" data-ajax-update=\"#px-expenses-page-container\" href=\"/PXControl/Reg/TimeExpenses/GeneralExpense?period=201152%20%20&amp;versionCode=U&amp;transId=32735&amp;statusFilter=All&amp;doSubmit=False\">edit</a><a data-ajax=\"true\" data-ajax-begin=\"Global.PersonalExpenses.saveFormData()\" data-ajax-method=\"POST\" data-ajax-mode=\"replace\" data-ajax-success=\"Global.PersonalExpenses.afterAjax()\" data-ajax-update=\"#px-expenses-page-container\" href=\"/PXControl/Reg/TimeExpenses/Delete?period=201152%20%20&amp;versionCode=U&amp;transId=32735&amp;category=General&amp;page=General\"><img src=\"/PXControl/Content/images/expenses/grid/delete_normal.png\" /></a>", 
       "TransId": "32735", 
       "IsValid": "1" 
      }, 
      { 
       "Status": "<img src='/PXControl/Content/images/expenses/grid/pe_status_saved.png' alt='SA' title='Saved' />", 
       "Type": "Travelcompclass F1 (F1)", 
       "ExpenseCategory": "<img src='/PXControl/Content/images/expenses/grid/mileage.png' alt='M' title='TaxMileage' />", 
       "Description": "$$changed price", 
       "Customer": "Construction Enterprice", 
       "Project": "301952 - Syncron International AB, löpande konsultation PX Control.", 
       "Activity": "10 - Ej debiterbar tid hos kund", 
       "NotesOrAttendees": "", 
       "Number": "100", 
       "IntendDate": "2011-12-27", 
       "CostInCurrency": "", 
       "Vat": "0,00", 
       "CostExchangeRate": "", 
       "Compensation": "340,00", 
       "CustomerPrice": "5000,00", 
       "Chargeability": "Yes", 
       "Actions": "<a class=\"edit-link\" data-ajax=\"true\" data-ajax-method=\"POST\" data-ajax-mode=\"replace\" data-ajax-success=\"Global.PersonalExpenses.afterAjax()\" data-ajax-update=\"#px-expenses-page-container\" href=\"/PXControl/Reg/TimeExpenses/Mileage?period=201152%20%20&amp;versionCode=U&amp;transId=32731&amp;statusFilter=All\">edit</a><a data-ajax=\"true\" data-ajax-begin=\"Global.PersonalExpenses.saveFormData()\" data-ajax-method=\"POST\" data-ajax-mode=\"replace\" data-ajax-success=\"Global.PersonalExpenses.afterAjax()\" data-ajax-update=\"#px-expenses-page-container\" href=\"/PXControl/Reg/TimeExpenses/Delete?period=201152%20%20&amp;versionCode=U&amp;transId=32731&amp;category=Mileage&amp;page=General\"><img src=\"/PXControl/Content/images/expenses/grid/delete_normal.png\" /></a>", 
       "TransId": "32731", 
       "IsValid": "1" 
      } 
     ] 
    }, 
    "scroll": 1, 
    "sortable": true, 
    "loadonce": true, 
    "viewrecords": true, 
    "userDataOnFooter": false, 
    "sortname": "TransId", 
    "sortorder": "desc", 
    "savesettingsurl": "/PXControl/Reg/TimeExpenses/SaveGridSettings", 
    "loadsettingsurl": "/PXControl/Reg/TimeExpenses/RevertGridSettings", 
    "grouping": false, 
    "groupingView": null, 
    "rowNum": 2147483647 
} 
+0

你幾乎沒有發佈JavaScript代碼,也沒有你的測試數據用來填充網格。你應該發佈* full *'gridDefinition'。 screenshort提供了一些信息,但不能用於重現您的問題。你另外使用'scroll:1','rownum','width:null',未知的'onSortCol'結尾等等。用回調'onSortCol:function(){return「stop」;例如,你可以防止任何列的排序。 – Oleg

+0

我評論了所有附加功能onSortCol等。我也設置滾動到0.但它仍然是相同的結果。你能告訴我在什麼地方jquery.jqGrid.src文件這個排序必須被解僱嗎? – Garik

+0

但是,當我在jqgrid創建後運行sortGrid implicity時,一切正常。 – Garik

回答

0

你怎麼能在the demo看到你發佈的代碼與排序沒有問題:

enter image description here

相關問題