<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m" controllerName="View.S1" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Use Of Filter">
<content>
<Table items="{/Record}" id="tab_IDD">
<headerToolbar>
<Toolbar>
<Label id="label_IDD" design="Bold" />
<ToolbarSpacer />
<SegmentedButton width="50%" id="segmented_IDDD"
select="Handle_Click_Segmented">
<items>
<SegmentedButtonItem text="Kids" key="kids" />
<SegmentedButtonItem text="Adults" key="adults" />
<SegmentedButtonItem text="Seniors" key="seniors" />
</items>
</SegmentedButton>
<ToolbarSpacer />
<ToggleButton text="Filter" press="onFilter_Butt"
type="Emphasized" id="toggle_ID" />
</Toolbar>
</headerToolbar>
<columns>
<Column visible="false">
<Text design="bold" text="Category" />
</Column>
<Column>
<Text design="bold" text="Name" />
</Column>
<Column>
<Text design="bold" text="Age" />
</Column>
<Column>
<Text design="bold" text="Mobile" />
</Column>
<Column>
<Text design="bold" text="Town" />
</Column>
</columns>
<ColumnListItem>
<cells>
<Text text="{recog}" />
<Text text="{name}" />
<Text text="{age}" />
<Text text="{mob}" />
<Text text="{town}" />
</cells>
</ColumnListItem>
</Table>
</content>
</Page>
</core:View>
sap.ui.controller("View.S1",
{
// Initialization...................
onInit : function() {
this.segButton = this.byId("segmented_IDDD");
this.segButton.setVisible(false);
this.JSOnModel = new sap.ui.model.json.JSONModel();
this.JSOnModel.loadData("Model/Data.json", null, false);
this.table_Id = this.byId("tab_IDD");
this.table_Id.setModel(this.JSOnModel);
this.labelId = this.byId("label_IDD");
this.labelId.setText("Records(" + this.table_Id.getItems().length+ ")")
},
// If you press Filter button then this event will fire.........
onFilter_Butt : function() {
if (!this.segButton.getVisible()) {
this.segButton.setVisible(true);
this.byId("toggle_ID").setText("Hide Filter");
this.segButton.setSelectedKey("kids");
this.Handle_Click_Segmented();
} else {
this.segButton.setVisible(false);
this.byId("toggle_ID").setText("Filter");
var bindallItems = this.table_Id.getBinding("items");
bindallItems.filter();
this.labelId.setText("Records("+ this.table_Id.getItems().length + ")");
}
},
// If you select Segmented button then this event will fire.........
Handle_Click_Segmented : function() {
var key_Paramenter = this.segButton.getSelectedKey();
this.filterArry = [];
var filter = new sap.ui.model.Filter("recog",
sap.ui.model.FilterOperator.Contains, key_Paramenter);
this.filterArry.push(filter);
var bindallItems = this.table_Id.getBinding("items");
bindallItems.filter(this.filterArry);
this.labelId.setText("Records(" + this.table_Id.getItems().length+ ")")
},
});
{"Record":[{"recog":"kids","name":"chintu","age":"6","mob":1111111111,"town":"mumbai"},
{"recog":"adults","name":"ritesh joshi","age":"30","mob":2222222222 ,"town":"gaya"},
{"recog":"seniors","name":"raj singh","age":"45","mob":3333333333 ,"town":"bathinda"},
{"recog":"kids","name":"patlu","age":"9","mob":4444444444 ,"town":"aurangabad"},
{"recog":"adults","name":"vikas kumar","age":"25","mob":5555555555 ,"town":"aurangabad"},
{"recog":"seniors","name":"raja singh","age":"44","mob":6666666666 ,"town":"madanpur"},
{"recog":"kids","name":"daya","age":"10","mob":7777777777 ,"town":"ranchi"},
{"recog":"seniors","name":"dharma raju","age":"56","mob":9999999999 ,"town":"bodhgaya"},
{"recog":"kids","name":"chuni","age":"5","mob":10000000000,"town":"gaya"},
{"recog":"adults","name":"nikhil kumar","age":"25","mob":3211111111 ,"town":"mumbai"},
{"recog":"seniors","name":"malik khan","age":"66","mob":121212121212 ,"town":"talwandi"},
{"recog":"kids","name":"luni","age":"2","mob":1313131313 ,"town":"navu mumbai"},
{"recog":"adults","name":"rohit kumar","age":"24","mob":1414141414 ,"town":"pune"},
{"recog":"seniors","name":"pavan reddy","age":"55","mob":1515151515 ,"town":"gaya"},
{"recog":"kids","name":"muni","age":"6","mob":1616161616 ,"town":"Kolkata"},
{"recog":"adults","name":"manoj kumar","age":"28","mob":1717171717 ,"town":"ramgrah"},
{"recog":"seniors","name":"udit paul","age":"55","mob":1818181818 ,"town":"gaya"},
{"recog":"kids","name":"nobita","age":"3","mob":1919191919 ,"town":"virar"},
{"recog":"adults","name":"lokesh kumar","age":"28","mob":2020202020 ,"town":"hazaribag"},
{"recog":"seniors","name":"lokesh rahul","age":"66","mob":2121212121 ,"town":"thane"},
{"recog":"kids","name":"juni","age":"3","mob":2222222222 ,"town":"nasik"},
{"recog":"adults","name":"vinay kumar","age":"33","mob":2323232323 ,"town":"gurgoan"},
{"recog":"seniors","name":"raj kishor","age":"77","mob":2424242424 ,"town":"banarash"},
{"recog":"kids","name":"shahan","age":"5","mob":2525252525 ,"town":"thane"},
{"recog":"adults","name":"raghu kumar","age":"27","mob":2626262626 ,"town":"noida"},
{"recog":"seniors","name":"shyam sundar","age":"44","mob":2727272727 ,"town":"bingunj"},
{"recog":"kids","name":"piku","age":"7","mob":2828282828 ,"town":"goregaon"},
{"recog":"adults","name":"prashant kumar","age":"26","mob":2929292929 ,"town":"patana"},
{"recog":"seniors","name":"ram kishor","age":"59","mob":3030303030 ,"town":"sasaram"}
]}
Index.html