cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Smart table Get all data from one entry

truckla
Explorer
0 Likes
4,002

Hi!

I implemented that you get the ID of the selected line (responive table) with one click and send them to another view.

With the help from mio.fujita

https://answers.sap.com/questions/13111243/smart-table-press-on-column-and-change-view.html#

onItemPress: function (oEvent) {
	var id = oEvent.getSource().getBindingContext().getProperty("ProductID");
	this.getOwnerComponent().getRouter().navTo("Detail", {
		id: id
	});
}

How do I get all entries that exist (of each line with this ID) with the read ID?

For example, I now have the ProductID from an order. How do I get the ordered goods or the quantity that is in a row with the read out ProductID?

Accepted Solutions (1)

Accepted Solutions (1)

MioYasutake
SAP Champion
SAP Champion

Hi truckla,

For example, you can get data using OData model's read operation.

var oModel = this.getView().getModel();
var oFilter = new Filter({
		path: "orderID",
		operator: sap.ui.model.FilterOperator.EQ,
		value1: "4"
	});
oModel.read("/Orders", {
	filters: [oFilter],
	success: function (oRes) {
		//here you can get data
	}
});

*If orderId is the unique key of your entity, you can just do this way:

oModel.read("/Orders('4')", {
	success: function (oRes) {
		//here you can get data
	}
});

oRes will be a JSON array like below.

Regards,

Mio

truckla
Explorer
0 Likes

Hi mio.fujita and thank you very much!

I don't understand where can I get my right value that is in your example "Orders" ? Where can I read it out from?

And where should I insert the code, in the onInit ?

If I try the root with "/" it doesn't work. I don't know where can I find the oModel.read("/Orders...

oModel2.read("/", {
                success: function (oRes) {
                    //here you can get data
                }
            });
MioYasutake
SAP Champion
SAP Champion
0 Likes

Hi Rick,

Let me clarify your requirement.

Your second view already shows the list of data which belong to order 4, and you want to send this data for further processing.

What is the trigger for sending the data? (button press, just after navigating to the second view...)

The path you specify in read request ( in below example, "/Orders" ) will be the entityset which is bound to the smartTable in the first view.

oModel.read("/Orders",

https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel%23methods/read

truckla
Explorer
0 Likes

Hi mio.fujita,

yes this is right.

It is now working, thank you!

Is there a way to get only all order ids from product id 04 from the oRes.results ?

My filter is not working.

MioYasutake
SAP Champion
SAP Champion
0 Likes

Hi Rick,

Great that the read request is now working!

Is your OData developed in SEGW project or from CDS?

In the case of SEGW, you need to implement filter operation in DPC_EXT class.

Also, make sure that "Filterable" attribute is checked in Entity definition.

filterable.png

truckla
Explorer
0 Likes

Hi mio.fujita

my OData is from CDS.

How can I access individual values of the oRes.results?
For example, if I need to get only all order ids from product id 04 from the oRes.results.

MioYasutake
SAP Champion
SAP Champion

You can for example use array's reduce function.

I'm assuming that you want to get values in below format.

>In the form order ID = 4; product IDs = 1,2,3,4; names= A,B,C,H; quantity= 1,1,2,56

var initalObj = { ProductId: [], ProductName: [] };
var oResult = oRes.results.reduce(function(acc, current) {
    acc.ProductId.push(current.ProductID);
    acc.ProductName.push(current.ProductName);
    return acc;
}, initalObj);					
console.log(oResult);

Here is what you'll get as oResult.

And the blow code will return the values concatenated by comma.

If you only want unique values, then you need to implement some check before pushing values into array.

    //check if the same value already exists in the array
    acc.ProductId.push(current.ProductID);
    acc.ProductName.push(current.ProductName);

Answers (1)

Answers (1)

truckla
Explorer
0 Likes

Hi mio.fujita,

maybe the example will make it clearer:

I have sent order ID 4 from the first view to the second view (already solved with your help).

Now the new view shows everything that exists for order ID 4:


Now I want to pass on this data or further process.
Everything about order ID 4.
In the form order ID = 4; product IDs = 1,2,3,4; names= A,B,C,H; quantity= 1,1,2,56

How do I do that?

How do I get the data?