0

Master Details Template

When click on Master[list] it will navigate to detail page with table data, suppose four column are there and an "Add" Button in the last column. Now what I want is, on click that "Add" button that row data will bind direct in cart view.

I tried using local storage, but how to call local stored data in cart view.

Cart view is on Master page with icon

On click cart icon view page is this

onPress: function(evt){
    localStorage.setItem('user', JSON.stringify({ 
        a : evt.oSource.oParent.mAggregations.cells[0].mProperties.src,
        b : evt.oSource.oParent.mAggregations.cells[1].mProperties.text,
        c : evt.oSource.oParent.mAggregations.cells[2].mProperties.text,
        d : evt.oSource.oParent.mAggregations.cells[3].mProperties.text 
    })); 
    user = JSON.parse(localStorage.getItem('user'));
}
Tim Gerlach
  • 3,390
  • 3
  • 20
  • 39
Mahendra Kulkarni
  • 1,437
  • 2
  • 26
  • 35
  • Please show us what you tried so far and try to make your question more concrete. – hirse May 18 '16 at 07:07
  • I have used local storage concept, but how to call it in cart view localStorage.setItem('user', JSON.stringify({ a : evt.oSource.oParent.mAggregations.cells[0].mProperties.src, b : evt.oSource.oParent.mAggregations.cells[1].mProperties.text, c : evt.oSource.oParent.mAggregations.cells[2].mProperties.text, d : evt.oSource.oParent.mAggregations.cells[3].mProperties.text })); user = JSON.parse(localStorage.getItem('user')); – Mahendra Kulkarni May 18 '16 at 07:10
  • Please edit the question and add this code to it instead of a comment. – hirse May 18 '16 at 07:14
  • Also see [this Q/A](http://stackoverflow.com/a/22842857/1969374) – Tim Gerlach May 18 '16 at 14:58

1 Answers1

0

I am assuming you are in a Component-based application using a UI5 Router and an ODataModel resp. Service.

You could just pass the id of your table entry onto the detail view via routing:

onAddBtnPressed : function(oEv) {
  var oRouter = sap.ui.core.UIComponent.getRouterFor(this),
      oContext = oEv.getSource().getBindingContext("your-model-name"),
      sDetailID = oContext.get("your-id-prop-name");
  oRouter.navTo("detail", {
    detailID: sDetailID
  })
}

from routing.config.routes:

{
  "pattern": "detail/{detailID}",
  "name": "detail",
  "target": "detail"
}

Note: {param} marks a parameter as mandatory while :param: is used for an optional parameter.

In your Detail.controller.js register a listener on routePatternMatched and implement it like this:

onRoutePatternMatched: function(oEv) {
  var sDetailID = oEv.getParameter("arguments").detailID;
  // create binding context on detail view
  this.getView().bindElement({
    "/YourDetailSet('"+ sDetailID +'")"
    model: "your-model-name"
  })
  // all the bindings in your detail view will no be relative to the above binding context.
}
cschuff
  • 5,502
  • 7
  • 36
  • 52