Friday, 10 February 2023

based on the table selection visible true false in sapui5(using json model)

 


view

     <!-- Button text, also retrieved from the i18n library -->

        text="{i18n>save}" 

        <!-- Name of the function that will be triggered when button is clicked -->

        press="onPressSave" 

        <!-- Determine the visibility of the button using the "visible" property -->

        visible="{json>/visible}" />


<!-- Define another button with emphasized style -->

<Button type="Emphasized" 

        <!-- Tooltip text, retrieved from the i18n library -->

        tooltip="{i18n>delete}" 

        <!-- Button text, also retrieved from the i18n library -->

        text="{i18n>delete}" 

        <!-- Name of the function that will be triggered when button is clicked -->

        press="onPressDelete" 

        <!-- Determine the visibility of the button using the "visible" property -->

        visible="{json>/visible}" />

or 


<!-- This code defines an OverflowToolbar element with a Transparent design -->

<OverflowToolbar design="Transparent">

    <!-- This element is a spacer, used to separate the two buttons -->

    <ToolbarSpacer />


    <!-- This button is an Emphasized type button with a tooltip and text set to internationalized values. 

         It also specifies a function to execute when pressed, and its enabled state is bound to a JSON model property -->

    <Button type="Emphasized" tooltip="{i18n>add}" text="{i18n>save}" press="onPressSave" enabled="{json>/visible}" />


    <!-- This button is similar to the first button, with a tooltip and text set to different internationalized values. 

         It specifies a different function to execute when pressed, and its enabled state is also bound to the same JSON model property -->

    <Button type="Emphasized" tooltip="{i18n>delete}" text="{i18n>delete}" press="onPressDelete" enabled="{json>/visible}" />

</OverflowToolbar>



 <Table id="listTable"  noDataText="{i18n>noresult}" mode="MultiSelect" selectionChange="onSelectionChange"/>


Controller
// Create a new instance of the JSONModel class var jsonmodel = new sap.ui.model.json.JSONModel({ // Property named "visible" set to false visible: false }); // Set the newly created JSON model as the data model for the current view // and give it the name "json" this.getView().setModel(jsonmodel, "json");




// Function that is triggered by a selection change event
onSelectionChange: function (oEvent) {
  // Save a reference to "this" for use within the function
  var that = this;
  
  // Check if there are any selected items in the event source
  if (oEvent.getSource().getSelectedContexts().length > 0) {
    // Set the "visible" property of the "json" model to true
    this.getView().getModel("json").setProperty("/visible", true);
    
    // Uncomment the following lines to show buttons with IDs "asave" and "adelate"
    // this.getView().byId("asave").setVisible(true);
    // this.getView().byId("adelate").setVisible(true);
  }
  else {
    // Uncomment the following lines to hide buttons with IDs "asave" and "adelate"
    // this.getView().byId("asave").setVisible(false);
    // this.getView().byId("adelate").setVisible(false);
    
    // Set the "visible" property of the "json" model to false
    this.getView().getModel("json").setProperty("/visible", false);
  }
},


No comments:

Post a Comment

test ganaral binding(testing )

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