Thursday, 21 July 2022

CRUD OPerations

 These are examples for CRUD OPerations


var oModel = this.getView().getModel();

Create Operation
====================================================================
var oPayload = {
"name":"name";
};


            oModel.create("/SampleSet", oPayload, {
method: "POST",
success: function (oData, oResponse) {

},
error: function (error, resp) {

}
});

Update  Operation
====================================================================

var oPayload = {
"name":"name";
};
var sPath =  "/SampleSet(SampleNumber='2084093745')";
oModel.update(sPath, oPayload{
method: "PUT",
success: function () {

},
error: function (oError) {

}
});



Read operation
====================================================================
var oName = "Raj"
var aFilter = [
new sap.ui.model.filter({"Name","EQ",oName})];
oModel.read("/sampleSet", {
filters: aFilter,
success: function (oData) {

},
error: function (oError) {

}
});

Delete Operation
====================================================================

var sPath =  "/SampleSet(SampleNumber='2084093745')";
oModel.remove(sPath, {
success: function () {

},
error: function (oError) {

}
});



Read operation
====================================================================
var oName = "Raj"
var aFilter = [
new sap.ui.model.filter({"Name","EQ",oName})];
oModel.read("/sampleSet", {
filters: aFilter,
success: function (oData) {

},
error: function (oError) {

}
});

Delete Operation
====================================================================

var sPath =  "/SampleSet(SampleNumber='2084093745')";
oModel.remove(sPath, {
success: function () {

},
error: function (oError) {

}
});


Monday, 24 January 2022

element binding sap.ui.table

 View

<mvc:View
    controllerName="projecteb.controller.View1"
    xmlns:ui="sap.ui.table"
    xmlns:mvc="sap.ui.core.mvc"
    displayBlock="true"
    xmlns="sap.m"
         
    xmlns:f="sap.ui.layout.form"
         
>
    <Shell id="shell">
        <App id="app">
            <pages>
                <Page id="page" title="{i18n>title}">
                    <content >
                  <ui:Table     rows="{/Customers}"  selectionMode="Single"   
 rowSelectionChange="onrowSelectionChange" >
                    <ui:columns>
                        <ui:Column width="11rem">
                        <Label text="CustomerID" />
                        <ui:template>
                            <Text text="{CustomerID}"   />
                        </ui:template>
                    </ui:Column>

                    <ui:Column width="11rem">
                        <Label text="CompanyName" />
                        <ui:template>
                            <Text text="{CompanyName}"   />
                        </ui:template>
                    </ui:Column>
                    <ui:Column width="11rem">
                        <Label text="ContactTitle" />
                        <ui:template>
                            <Text text="{ContactTitle}"   />
                        </ui:template>
                    </ui:Column>
                    <ui:Column width="11rem">
                        <Label text="ContactName" />
                        <ui:template>
                            <Text text="{ContactName}"   />
                        </ui:template>
                    </ui:Column>
                        </ui:columns>
                  </ui:Table>


                    <f:SimpleForm id="SimpleFormDisplay354"
            editable="true" >
            <f:content>
                <Label text="CustomerID" />
                <Input id="CustomerID" value="{CustomerID}" />
                <Label text="CompanyName" />
                <Input value="{CompanyName} " />
                <Label text="ContactTitle" />
                <Input value="{ContactTitle}  " />
                <Label text="ContactName" />
                <Input id="ContactName" value="{ContactName}" />
            </f:content>
        </f:SimpleForm>
                    </content >
                </Page>
            </pages>
        </App>
    </Shell>
</mvc:View>


Controller:

sap.ui.define([
    "sap/ui/core/mvc/Controller"
],
    /**
     * @param {typeof sap.ui.core.mvc.Controller} Controller
     */
    function (Controller) {
        "use strict";

        return Controller.extend("projecteb.controller.View1", {
            onInit: function () {},
            onrowSelectionChange: function (oEvent) {
              var oRow = oEvent.getParameter("rowContext");
              var sPath = oRow.getPath();
              var oFORM = this.getView().byId("SimpleFormDisplay354");
              oFORM.bindElement(sPath)
            }
        });
    });


or

 onInit: function () {},
            onrowSelectionChange: function (oEvent) {
            //   var oRow = oEvent.getParameter("rowContext");
            //   var sPath = oRow.getPath();
            //   var oFORM = this.getView().byId("SimpleFormDisplay354");
            //   oFORM.bindElement(sPath)
            var oRow = oEvent.getParameter("rowContext");
            var oFORM = this.getView().byId("SimpleFormDisplay354");
            oFORM.bindElement(oRow.sPath)
            }
        });
    });


Tuesday, 18 January 2022

sapui5 read operation

 view

  <content>
                      <Table items="{/Employees}"  >
        <columns>
            <Column>
                <Text text="EmployeeID"></Text>
            </Column>
            <Column>
                <Text text="LastName"></Text>
            </Column>
            <Column minScreenWidth="Tablet">
                <Text text="Address"></Text>
            </Column>
            <Column minScreenWidth="Tablet" demandPopin="true">
                <Text text="City"></Text>
            </Column>
        </columns>
        <items>
            <ColumnListItem>
                <cells>
                    <Text text="{EmployeeID}"></Text>
                    <Input value="{LastName}"></Input>
                    <Text text="{Address}"></Text>
                    <Text text="{City}"></Text>
                </cells>
            </ColumnListItem>
        </items>
    </Table>  

    <Input value="{crud>/Country}"></Input>


     <Table items="{crud>/}" id="abc" >
        <columns>
            <Column>
                <Text text="EmployeeID"></Text>
            </Column>
            <Column>
                <Text text="LastName"></Text>
            </Column>
            <Column minScreenWidth="Tablet">
                <Text text="Title"></Text>
            </Column>
            <Column minScreenWidth="Tablet" demandPopin="true">
                <Text text="FirstName"></Text>
            </Column>
        </columns>
        <items>
            <ColumnListItem>
                <cells>
                    <Text text="{crud>EmployeeID}"></Text>
                    <Input value="{crud>LastName}"></Input>
                    <Text text="{crud>Title}"></Text>
                    <Text text="{crud>FirstName}"></Text>
                </cells>
            </ColumnListItem>
        </items>
    </Table>  
                    </content>

Controller

sap.ui.define([
    "sap/ui/core/mvc/Controller"
],
    /**
     * @param {typeof sap.ui.core.mvc.Controller} Controller
     */
    function (Controller) {
        "use strict";

        return Controller.extend("project123.controller.View1", {
            onInit: function () {
                //     var oModel = new sap.ui.model.odata.v2.ODataModel("/V2/Northwind/Northwind.svc");
                //     var oThis = this;
                //     oModel.read("/Employees(1)", {
                //         success: function (oData) {
    
                //             var ocrud = new sap.ui.model.json.JSONModel({
                //                 Country: oData.Country
    
                //             });
    
                //             oThis.getView().setModel(ocrud, "crud");
                //         },
                //         error: function (oData) {
    
                // }
how to get a model in a controller

 // var data =this.getOwnerComponent().getModel("raja");
or
var data = this.getView().getModel("raja" );
var json = new JSONModel();
var oThis=this;
data.read("/Customers",{
     success: function (oData){
     debugger;
json.setData(oData.results);
oThis.getView().byId("abc").setModel(json, "crud");
}




                var oModel = new sap.ui.model.odata.v2.ODataModel("/V2/Northwind/Northwind.svc");
                var ocrud = new sap.ui.model.json.JSONModel();
                var oThis = this;
                oModel.read("/Employees", {
                    success: function (oData) {
    
                       ocrud.setData(oData.results);
    
                        oThis.getView().byId("abc").setModel(ocrud"crud");
                    },
                    error: function (oData) {
    
            }
    
            });
        },
        });
    })
    

test ganaral binding(testing )

  /home/user/projects/project1/webapp/model/record.json: {     "text" : "outer text" ,     "myrecorsd" : [    ...