2016-09-29 21 views
0

此排序是下面的代碼,我使用:在擴展菲奧裏應用

getHeaderFooterOptions: function() { 
    var that = this; 

    var oHeaderFooterOptions = { 
     sI18NMasterTitle: "MASTER_TITLE", 
     buttonList: [] 
    }; 

    oHeaderFooterOptions.oFilterOptions = { 
     onFilterPressed: jQuery.proxy(that.onShowFilter, that) 
    }; 

    var sortItems = []; 
    var sortText=null; 
    var sortKey = null; 
    var sortKey = "WiCreatedAt"; 
    sortItems.push({ 
     key: "WiCreatedAt", 
     text: "Descending" 
    }); 
    sortItems.push({ 
     key: "WiCreatedAt", 
     text: "Ascending" 
    }); 

    oHeaderFooterOptions.oSortOptions = { 
     aSortItems: sortItems, 
     sSelectedItemKey: "WiCreatedAt", 
     onSortSelected: jQuery.proxy(that.handleSort, that) 
    }; 

    return oHeaderFooterOptions; 
}, 

handleSort: function(sSortKey) { 
    //alert("msg"); 
    if (sSortKey === "WiCreatedAt") { 
     oSorter = new sap.ui.model.Sorter(sSortKey,false); 
    } 

    else if (sSortKey === "WiCreatedAt" ) { 
     oSorter = new sap.ui.model.Sorter(sSortKey, true); 
    } 
    this.getList().getBinding("items").sort(oSorter); 
}, 

有什麼辦法,我們也可以通過文字我們傳遞的關鍵在oHeaderFooterOptions.oSortOptions對象的方式,以及如何我們是否獲得像aSortItems和sSelectedItemKey這樣的屬性,是否有這樣的API?

+0

我想根據密鑰「WiCreatedAt」按升序和降序對主列表中的項進行排序。任何人都可以請指導我如何修改我的代碼並獲得所需的結果。 –

回答

1

我們嘗試瞭解問題。請看下面的代碼:

getHeaderFooterOptions: function() { 
    var that = this; 

    var oHeaderFooterOptions = { 
     sI18NMasterTitle: "MASTER_TITLE", 
     buttonList: [] 
    }; 

    oHeaderFooterOptions.oFilterOptions = { 
     onFilterPressed: jQuery.proxy(that.onShowFilter, that) 
    }; 

    var sortItems = []; 
    var sortText=null; 

    sortItems.push({ 
     key: "Descending", 
     text: "WiCreatedAt sorted descending" 
    }); 
    sortItems.push({ 
     key: "Ascending", 
     text: "WiCreatedAt sorted ascending" 
    }); 

    oHeaderFooterOptions.oSortOptions = { 
     aSortItems: sortItems, 
     sSelectedItemKey: "WiCreatedAt", 
     onSortSelected: jQuery.proxy(that.handleSort, that) 
    }; 

    return oHeaderFooterOptions; 
}, 

handleSort: function(sSortKey) { 
    //alert("msg"); 
    if (sSortKey === "Ascending") { 
     oSorter = new sap.ui.model.Sorter("WiCreatedAt",false); 
    } 

    else if (sSortKey === "Descending" ) { 
     oSorter = new sap.ui.model.Sorter("WiCreatedAt", true); 
    } 
    this.getList().getBinding("items").sort(oSorter); 
}, 

另請參閱SAP WebIDE中的示例應用程序「管理產品」。

+0

你好,感謝您的幫助。但我的問題是,如果我必須根據一個鍵來升序和降序排序,那麼我將如何繼續? –

+0

它看起來像代碼應該工作。如果您遇到錯誤,您可以更詳細地解釋您收到的錯誤? –