cancel
Showing results for 
Search instead for 
Did you mean: 

"Move" content of table to a new view

michael_fallenbchel
Active Participant
0 Kudos

Hi experts,

playing around with table and popups.


What I haave at the moment:

a table (sap.ui.table.Table), binded to a gateway service (oTable.bindRows("/HeaderSet"), with a ODataModel (sap.ui.getCore().byId("Header").setModel(oModel);)

Now I have added a column to this table where I can enter some data (in my case quantity).

Top of the table,I have a button "Save", which opens a new view in a popup (sap.ui.ux3.OverlayDialog).

This Popup also includes a table.

What I want - show in this new view all data from view1, where something is entered in my column.

The data is not in SAP, something internal, I just want to show these lines where I have entered a quantity.

How to do this?

Thanks

Michael

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Is that new column input field for qty bound to the model?

michael_fallenbchel
Active Participant
0 Kudos

Yes, it's bounded to the model

former_member182372
Active Contributor
0 Kudos

var itemsModel = {};

Object.defineProperty(itemsModel, "ChangedItems", {

  get: function () {

  return $.map(

  $.grep(

  oTable.getBinding("rows").getContexts(),

  function( context, i ) {

  if (context.getObject().<NAME OF QTY PROPERTY >) {

  return  true;

  }

  return false;

  }),

  function(context, j) {

  return context.getObject();

  });

  }

});


var jModel = new sap.ui.model.json.JSONModel(itemsModel);

sap.ui.getCore().setModel(jModel, "ChangedItemsModel");

In a popup set model to table and bind a table rows to "ChangedItemsModel>/ChangedItems" CdsfgdshangedItemsModel

michael_fallenbchel
Active Participant
0 Kudos

Wow, alsmost done...have added your coding, everythings working, but my field is always empty.

How I defined the textfield:


var oQty = new sap.ui.commons.TextField({

  }

  ).bindProperty("value","menge", function(cellValue){

  $('#' +  this.getId()).css("background-color","yellow");

  return cellValue;

  });

oTable.addColumn(new sap.ui.table.Column({

  label : new sap.ui.commons.Label({

  id   : "menge",

  text : "TEST"

  }),

  template: oQty,

  width : "10%",

  }));

I think something is missing here?

former_member182372
Active Contributor
0 Kudos

bindProperty("value","ChangedItemsModel>menge"......

michael_fallenbchel
Active Participant
0 Kudos

This is how i bind the field in "view1"

kai2015
Contributor
0 Kudos

former_member182372
Active Contributor
0 Kudos

what is view1? ChangedItemsModel is a pseudo-model, you should not use it in original table where you enter data, only in preview popup

michael_fallenbchel
Active Participant
0 Kudos

view1 is my first table (binding via OData).

Here I have added the textfield, binding to "menge".

In the second view (the popup) i bind the pseudo model (the JSON one)

former_member182372
Active Contributor
0 Kudos

>>This is how i bind the field in "view1"

I am confused, view1 is first table but you have a pseudo model binding(ChangedItemsModel>menge) there.

view1 should have regular Odata model binsing

popup should have binding to pseudo model ChangedItemsModel

would be much more efficient to see a code

michael_fallenbchel
Active Participant
0 Kudos

view1:


var oTable = new sap.ui.table.Table({

  id : "oTable",

  height : "100%",

  visibleRowCountMode : sap.ui.table.VisibleRowCountMode.Auto,

  editable : false,

  //NavigationMode: sap.ui.table.NavigationMode.Scrollbar,

  //selectionMode : sap.ui.table.SelectionMode.None,

  }

});

oController.addCol(oTable, "Kontrakt", "konnr", "30%");

(.....)

var oQty = new sap.ui.commons.TextField({

  }

).bindProperty("value","menge", function(cellValue){

  $('#' +  this.getId()).css("background-color","yellow");

  return cellValue;

  });

oTable.addColumn(new sap.ui.table.Column({

  label : new sap.ui.commons.Label({

  id   : "menge",

  text : "Conf."

  }),

  template: oQty,

  width : "15%",

}));

(........)

oTable.bindRows("/HeaderSet");

Then comes your part (with the itemsModel, JSON model)

Popup code:


var oTable = new sap.ui.table.Table({

height : "100%",

  visibleRowCountMode : sap.ui.table.VisibleRowCountMode.Auto,

  editable : false,

  //NavigationMode: sap.ui.table.NavigationMode.Scrollbar,

  //selectionMode : sap.ui.table.SelectionMode.None,

  }

});

oTable.addColumn(new sap.ui.table.Column({

  label: new sap.ui.commons.Label({

  text: "Beleg"}),

  template: new sap.ui.commons.TextView({

  text: "{ChangedItemsModel>/ChangedItems>ebeln}"})

  }));

oTable.bindRows("ChangedItemsModel>/ChangedItems");

former_member182372
Active Contributor
0 Kudos
  1. oTable.addColumn(new sap.ui.table.Column({ 
  2.   label: new sap.ui.commons.Label({ 
  3.   text: "Beleg"}), 
  4.   template: new sap.ui.commons.TextView({ 
  5.   text: "{ChangedItemsModel>ebeln}"}) 
  6.   }));

and may be add but not sure it is 100% needed


  1. oTable.setModel(sap.ui.getCore().getModel("ChangedItemsModel"), "ChangedItemsModel"); 
michael_fallenbchel
Active Participant
0 Kudos

I'm too stupid 😞

pls see attached my coding - something's wrong

former_member182372
Active Contributor
michael_fallenbchel
Active Participant
0 Kudos

http://jsbin.com/yevanebaqe/2/edit

See - I have added a colum where I can enter the quantity...depending on this, the second table should be updated.

That's exactly my problem - when I use a binded field, the coding will check the binding value (menge_conf), not the vlaue I have entered here.

former_member182372
Active Contributor
michael_fallenbchel
Active Participant
0 Kudos

Hi,

sorry for my late reply, was on different business trips last week(s).

Okay, what I have done now - copied the whole code to a new eclipse project to see if it's working.

Fine, doing what I want.

Now I only replaced the model by my oData part:


odataUrl = "/sap/opu/odata/sap/ZWWW_TESTONLY/";

var odataUser = "remoteuser";

var odataPass = "remotepass";

var oModel = new sap.ui.model.odata.ODataModel(odataUrl, false, odataUser, odataPass);

sap.ui.getCore().setModel(oModel);

And now it's not working anymore - its showing the data as expected in first view on top, when I enter some data in the confirmed qty field nothing is happening...

Damn"!

michael_fallenbchel
Active Participant
0 Kudos

Got it!

With a little bit playing around (mapping oData to JSON...) everything's working now 🙂

Thanks all for your support

former_member182372
Active Contributor
0 Kudos

Well, close the thread, reward points 😉

Answers (2)

Answers (2)

kedarT
Active Contributor
0 Kudos

Hi Micheal,

As Kai Helferich said you could loop through the table in view1 and populate the same into a empty JSON model  and then bind this model to the table in view2.

Hope this helps.

kai2015
Contributor
0 Kudos

In this case, I would generate new data, by looping the data of the model from view1 and select only those rows which you mentioned. Then set this new data to the model of view2/dialog.

Maybe there is a better way.

EDIT: To the community: Something like XPATH would be nice for oData Path. Or is there already a functionality like that?