cschuff
cschuff

Reputation: 5542

sap.ui.table - FilterType on Column not working

The filterType property of sap.ui.table.Column does not appear to work for me. Here is my code:

<table:Column sortProperty="abc" filterProperty="abc" filterType="sap.ui.model.type.Integer">  
    <table:label>  
        <Label text="abc"></Label>  
    </table:label>  
    <table:template>  
        <Label text="{modelName>abc}"></Label>  
    </table:template>  
</table:Column>  

abc is containing a number as a string e.g. "10". The values are showing in the table so the bindings are correct.

Sorting also works but it does not respect the Integer type. I still get a String like sorting so that the entry "6" shows after "10" for an ascending sort. The column is even returning the filterType I set if I do sap.ui.getCore().byId("columnId").getFilterType(); What the heck is wrong here?

BR Chris

Upvotes: 0

Views: 3236

Answers (2)

cschuff
cschuff

Reputation: 5542

To finally answer this: The filterType is NOT taken into account for sorting, no matter which view type you use. If you also think there should be a way to easily influence the sort logic you can support the issue here: https://github.com/SAP/openui5/issues/192

Upvotes: 1

Haojie
Haojie

Reputation: 5713

It is working for the code snippet. You can click the column header to sort by descending or ascending and filter value.Please check.

<script id='sap-ui-bootstrap' type='text/javascript' src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js' data-sap-ui-libs="sap.m,sap.ui.commons,sap.ui.table,sap.viz" data-sap-ui-theme="sap_bluecrystal"></script>

<script id="view1" type="sapui5/xmlview">
    <mvc:View xmlns:core="sap.ui.core" xmlns:layout="sap.ui.commons.layout" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.ui.commons" xmlns:table="sap.ui.table" controllerName="my.own.controller" xmlns:html="http://www.w3.org/1999/xhtml">

        <table:Table id="testTable" rows="{/}">
            <table:Column sortProperty="abc" filterProperty="abc" filterType="sap.ui.model.type.Integer">
                <table:label>
                    <Label text="abc"></Label>
                </table:label>
                <table:template>
                    <Label text="{abc}"></Label>
                </table:template>
            </table:Column>
            <table:Column>
                <table:label>
                    <Label text="abc2"></Label>
                </table:label>
                <table:template>
                    <Label text="{abc2}"></Label>
                </table:template>
            </table:Column>
        </table:Table>
    </mvc:View>
</script>


<script>
    sap.ui.controller("my.own.controller", {
        onInit: function() {
            var aTableData = [{
                abc: 1,
                abc2: "a"
            }, {
                abc: 6,
                abc2: "b"

            }, {
                abc: 10,
                abc2: "c"

            }, {
                abc: 3,
                abc2: "g"

            }, {
                abc: 12,
                abc2: "h"

            }];
            var oTableModel = new sap.ui.model.json.JSONModel();
            oTableModel.setData(aTableData);

            var oTable = this.getView().byId("testTable");
            oTable.setModel(oTableModel);
            oTable.sort(oTable.getColumns()[0]);
        }


    });

    var myView = sap.ui.xmlview("myView", {
        viewContent: jQuery('#view1').html()
    }); // 
    myView.placeAt('content');
</script>

</head>

<body class='sapUiBody'>
    <div id='content'></div>
</body>

Upvotes: 1

Related Questions