使用sap.ui.table.Table排序和过滤问题

时间:2016-12-06 07:51:59

标签: sapui5

我遇到了在分组后对sap.ui.table.Table进行排序的问题。任何人都可以在分组后进行排序?我已尝试过SAP Developer Network(SCN)的几个提示,但它不起作用。

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>SAPUI5 Table column sorter demo</title>
    </head>
<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">
        <layout:VerticalLayout>
            <Button text="Reset" press="onPress" />
            <table:Table id="testTable" rows="{/}" enableGrouping="true">
                <table:Column sortProperty="abc3" visible="true">
                    <table:label>
                        <Label text="abc3"></Label>
                    </table:label>
                    <table:template>
                        <Label text="{abc3}"></Label>
                    </table:template>
                </table:Column>
                <table:Column sortProperty="abc2">
                    <table:label>
                        <Label text="abc2"></Label>
                    </table:label>
                    <table:template>
                        <Label text="{abc2}"></Label>
                    </table:template>
                </table:Column>
                 <table:Column sortProperty="abc" visible="true">
                    <table:label>
                        <Label text="abc"></Label>
                    </table:label>
                    <table:template>
                        <Label text="{abc}"></Label>
                    </table:template>
                </table:Column>
            </table:Table>
        </layout:VerticalLayout>
    </mvc:View>
</script>


<script>
    sap.ui.controller("my.own.controller", {
        onInit: function() {
             var aTableData = [{
                abc: 1, abc2: "a",abc3: "d"}, {
                abc: 4, abc2: "b",abc3: "a"}, {
                abc: 5, abc2: "a",abc3: "a"}, {
                abc: 2, abc2: "c",abc3: "a"}, {
                abc: 7, abc2: "g",abc3: "a"}, {
                abc: 1, abc2: "d",abc3: "a"}, {
                abc: 11, abc2: "c",abc3: "d"}, {
                abc: 2, abc2: "d",abc3: "b"}, {
                abc: 9, abc2: "e",abc3: "d"}, {
                abc: 10, abc2: "a",abc3: "b"}, {
                abc: 8, abc2: "f",abc3: "d"}, {
                abc: 5, abc2: "a",abc3: "d"}, {
                abc: 7, abc2: "b",abc3: "c"}, {
                abc: 6, abc2: "a",abc3: "d"}, {
                abc: 3,abc2: "h",abc3: "d" }];
            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]);
        },
        onPress: function() {
            var oTable = this.getView().byId("testTable");
            //set group of table and column to false
            oTable.setEnableGrouping(false);
            oTable.getColumns()[0].setGrouped(false);
            var oModel = oTable.getModel();

            var oListBinding = oTable.getBinding();
            oListBinding.aSorters = null;
            oListBinding.aFilters = null;
            oModel.refresh(true);
            //after reset, set the enableGroup back to true
            oTable.setEnableGrouping(true);
          oTable.sort(oTable.getColumns()[0]);
          oTable.sort(oTable.getColumns()[1]);
        }
    });
    var myView = sap.ui.xmlview("myView", {
        viewContent: jQuery('#view1').html()
    }); // 
    myView.placeAt('content');
</script>

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

对分组后的未分组列进行排序不起作用,如下所示:

Sort after Group

1 个答案:

答案 0 :(得分:0)

您是否已经检查了聚合绑定的排序,分组和过滤? https://sapui5.hana.ondemand.com/#docs/guide/ec79a5d5918f4f7f9cbc2150e66778cc.html

有了这个,您可以进行初始排序,也可以手动排序......