SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.95k stars 1.24k forks source link

sap.ui.model.odata.v2 operationMode:client sort issue #1094

Closed hschaefer123 closed 2 years ago

hschaefer123 commented 8 years ago

OpenUI5 version: 1.38.4

Browser/version (+device/version): chrome

Any other tested browsers/devices(OK/FAIL): not tested

I am currently binding an odata v2 entityset to a sap.m.list.

<List id="lineItemsList" 
    noDataText="{i18n>detailLineItemTableNoDataText}" 
    busyIndicatorDelay="{detailView>/lineItemTableDelay}"
    updateFinished="onListUpdateFinished"
    items="{
        path: 'MeasurementDocuments',
        sorter: [
            {
                path: 'Pttxt',
                descending: false,
                group: true
            }, {
                path: 'Idate',
                descending: true
            }, {
                path: 'Itime',
                descending: true
            }
        ],
        groupHeaderFactory: '.getGroupHeader',
        parameters: {
            operationMode: 'Client'
        }
    }">

For performance reason i would like to use client side sorting/filtering. Inside controller, i am calling the binding sort function this way

onSelectViewMode: function(oEvent) {
    var sKey = oEvent.getParameter("key"),
        oList = this.getView().byId("lineItemsList"),
        oListBinding = oList.getBinding("items");

    if (sKey === "DATE") {
        oListBinding.sort([
            {
                path: "Idate",
                descending: true,
                group: true
            }, {
                path: "Itime",
                descending: true
            }, {
                path: "Pttxt",
                descending: false
            }
        ]);
    } else if (sKey === "TYPE") {
        oListBinding.sort([
            {
                path: "Pttxt",
                descending: false
            }, {
                path: "Idate",
                descending: true
            }, {
                path: "Itime",
                descending: true
            }
        ]);
    }
}

I got the following error:

ODataMetadata.js:6 Uncaught TypeError: Cannot read property 'replace' of undefined

...
    /**
    *  extract the property metadata of a specified property of a entity type out of the metadata document
    */
    ODataMetadata.prototype._getPropertyMetadata = function(oEntityType, sProperty) {
        var oPropertyMetadata, that = this;

        if (!oEntityType) {
            return;
        }

        // remove starting/trailing /
        sProperty = sProperty.replace(/^\/|\/$/g, ""); // <-- error is here because property is empty
...

Inside debugger, sProperty is undefined!

Any ideas?

I think, client side sorting/filtering should be supported out-of-the-box, or am i doing something wrong?

What is the expected result? The client should sort the resultset clientside

What happens instead? Thrown error

Maybe you got an idea what is causing the issue. If not, please let me know and i have to create a working example with the issue inside.

Regards Holger

TobiasOetzel commented 8 years ago

Hi,

thanks for the ticket! reproduceable in this jsbin tracked internally 1680214612

best regards, Tobias

hschaefer123 commented 8 years ago

Hi Tobias, BTW: is it possible, that grouping is also buggy (even using without clientmode?).

We have implemented server side sorting for the upper szenario, but switching between the two sort szeanrios only initially shows the list grouping. All other switches only show plain list items?!?

I also tried setting whole setItemBinding() instead of binding.sort(), but same result.

Regards Holger

TobiasOetzel commented 8 years ago

Hi Holger, clientside: Grouping is a special kind of sorting. I would expect it to be broken in a similar way.

server side: should work - in your example you modified to group to xgroup: true is it such a small thing?

Best regards, Tobias

hschaefer123 commented 8 years ago

Hi Tobias, it still does not work even without the copy/paste type error ;-)

see http://jsbin.com/vecasoj/edit?html,output

I think, the group doe not work if using binding (or am i doing something wrong?). For me, it only works the first time with inline template inside xml view. After changing sort order (or in this case using scripting, the group will not be used).

I will create a ticket to see, if this is buggy!

Regards Holger

wdwall2 commented 6 years ago

Hi, i am trying the same thing following directly instructions in the SAPui51 course. And i get exactly the same problem. Has it been fixed? what version of libraries shall i use to get the fix? thankxs and regards Wolf

RandomByte commented 6 years ago

Hi Wolf,

Unfortunately our internal tracking incident 1680214612 mistakenly got closed as duplicate.

I created 1880177368 internally. The responsible colleagues will provide feedback on this issue soon.

Best regards, Merlin

wdwall2 commented 6 years ago

Hi Merlin, looking at the code in this issue i actually have only a simple search field and a pretty trivial callback. Might i help you in providing my coding? the app is very simple because it is just the excercises of the ui51 course . just let me know in case i can attach it here. Kind regards wolf

RandomByte commented 6 years ago

Does your code create a binding with operationMode: 'Client' as well?

If yes, feel free to share your code as a jsbin or similar. If no, your issue might be unrelated to this one.

wdwall2 commented 6 years ago

actually my binding is on an odata service i try to perform a search using search field and creating a filter object that is added to the binding. The property i'm filtering for is not searchable on the odata model itself so it perform the "client mode" filtering internally.

kind regards

tobiasso85 commented 6 years ago

Hi Wolf,

I've found the following lines in the openui5 course: openSAP_ui51_Week_2_Unit_4 page 4 (course exercise)

<List id="productsList" items="{ path : '/ProductSet', sorter : { path : 'Category', group : true } }">

This sorter is defined within the XML Template and resolved from the BindingParser which is slightly different than creating the sorter manually. Because when parsing the template a Sorter is created internally using the properties

When the sorter is passed to the Binding it needs to be created manually and the "code" from the template cannot be used. Instances of sap.ui.model.Sorter need to be passed to the Binding then. @see https://blogs.sap.com/2013/11/29/custom-sorter-and-grouper/ @see https://sapui5.hana.ondemand.com/#/api/sap.ui.model.Sorter @see https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataListBinding

sorter: [new sap.ui.model.Sorter("CategoryName", false, true), new sap.ui.model.Sorter("ProductName", true)] correct version //note the grouping comparison needs to be implemented

Kind regards Tobias

wdwall2 commented 6 years ago

Hi Tobias, thank you, you are so very kind. Actually i am not using a sorter but a filter. SAPUI51 course week 2 unit 4 ` <List id="productsList" items="{/ProductSet}">

<ToolbarSpacer/> <SearchField width="50%" search="onFilterProducts"/> </Toolbar> </headerToolbar>` ``` onFilterProducts : function (oEvent) { // build filter array var aFilter = [], sQuery = oEvent.getParameter("query"), // retrieve list control oList = this.getView().byId("productsList"), // get binding for aggregation 'items' oBinding = oList.getBinding("items"); if (sQuery) { aFilter.push(new Filter("ProductID", FilterOperator.Contains, sQuery)); } // apply filter. an empty filter array simply removes the filter // which will make all entries visible again oBinding.filter(aFilter); } ``` In debug all variables are read and filled correctly, but Whan i call the oBinging.Filter, i get this internal error: Uncaught TypeError: Cannot read property 'replace' of undefined at constructor.a._getPropertyMetadata (ODataMetadata-dbg.js:848) at Function.c._createFilterSegment (ODataUtils-dbg.js:389) at f.<anonymous> (ODataUtils-dbg.js:138) at Function.each (jquery-dbg.js:365) at Array.<anonymous> (ODataUtils-dbg.js:117) at Function.each (jquery-dbg.js:371) at Function.c._createFilterParams (ODataUtils-dbg.js:113) at Function.c.createFilterParams (ODataUtils-dbg.js:74) at constructor.h.createFilterParams (ODataListBinding-dbg.js:1315) at constructor.h.filter (ODataListBinding-dbg.js:1255) a._getPropertyMetadata @ ODataMetadata-dbg.js:848 c._createFilterSegment @ ODataUtils-dbg.js:389 (anonymous) @ ODataUtils-dbg.js:138 each @ jquery-dbg.js:365 (anonymous) @ ODataUtils-dbg.js:117 each @ jquery-dbg.js:371 c._createFilterParams @ ODataUtils-dbg.js:113 c.createFilterParams @ ODataUtils-dbg.js:74 h.createFilterParams @ ODataListBinding-dbg.js:1315 h.filter @ ODataListBinding-dbg.js:1255 onSubmit @ App.controller.js?eval:92 a.fireEvent @ EventProvider-dbg.js:228 a.fireEvent @ Element-dbg.js:427 (anonymous) @ ManagedObjectMetadata-dbg.js:428 r.onsapenter @ Input-dbg.js:1534 a._handleEvent @ Element-dbg.js:162 U._handleEvent @ UIArea-dbg.js:828 dispatch @ jquery-dbg.js:4737 c3.handle @ jquery-dbg.js:4549 I'll try stackoverflow because i cannot imagine this is really a bug. Thanks and regards wolf </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/tobiasso85"><img src="https://avatars.githubusercontent.com/u/25656984?v=4" />tobiasso85</a> commented <strong> 6 years ago</strong> </div> <div class="markdown-body"> <p>Hi wolf, can you check the value of aFilter[0].sPath right before calling oBinding.filter? For me the filtering works. Maybe try to change "ProductID" to "ProductId".</p> <p>Regards Tobias</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/wdwall2"><img src="https://avatars.githubusercontent.com/u/36133221?v=4" />wdwall2</a> commented <strong> 6 years ago</strong> </div> <div class="markdown-body"> <p>Hi Tobias, you are right it is sPath empty. there was an attribute sName instead. I got it working playing around with the order of filter and filterOperations in the sap.define... but it makes no sense to me. I'm quite puzzled, but i believe it belongs to my learning curve. Thanks for your support kind regards wolf</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/tobiasso85"><img src="https://avatars.githubusercontent.com/u/25656984?v=4" />tobiasso85</a> commented <strong> 6 years ago</strong> </div> <div class="markdown-body"> <p>Hi Wolf,</p> <p>could you create a jsbin or paste your working code here, so that one can compare before and after and also have a solution?</p> <p>Regards Tobias</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/flovogt"><img src="https://avatars.githubusercontent.com/u/34711402?v=4" />flovogt</a> commented <strong> 2 years ago</strong> </div> <div class="markdown-body"> <p>Since there is no response from the author for more than 4 weeks I'm closing the ticket.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/wdwall2"><img src="https://avatars.githubusercontent.com/u/36133221?v=4" />wdwall2</a> commented <strong> 2 years ago</strong> </div> <div class="markdown-body"> <p>Hi, it's 4 years old :-D not 4 weeks</p> <p>regards</p> <p>Il giorno mer 4 mag 2022 alle ore 09:09 Florian Vogt < <strong><em>@</em></strong>.***> ha scritto:</p> <blockquote> <p>Since there is no response from the author for more than 4 weeks I'm closing the ticket.</p> <p>— Reply to this email directly, view it on GitHub <a href="https://github.com/SAP/openui5/issues/1094#issuecomment-1116993113">https://github.com/SAP/openui5/issues/1094#issuecomment-1116993113</a>, or unsubscribe <a href="https://github.com/notifications/unsubscribe-auth/AITVSZMHOM6VHSZXKPH56LLVIIPBFANCNFSM4CL3SBXQ">https://github.com/notifications/unsubscribe-auth/AITVSZMHOM6VHSZXKPH56LLVIIPBFANCNFSM4CL3SBXQ</a> . You are receiving this because you commented.Message ID: <strong><em>@</em></strong>.***></p> </blockquote> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>